Git Commands

A Reference Guide

Git Branch Commands


  • git branch - Display a list of the local branches in your Git repository.
  • git branch -a - Display a list of both local branches and remote branches in your Git repository.
  • git branch -c - Copy a Git branch.
  • git branch -d <branch-name> - Delete a local Git branch. This command will not work if the branch you are attempting to delete has unmerged changes.
  • git branch -D <branch-name> - Delete a local Git branch with unmerged changes.
  • git branch -m <branch-name> <new-branch-name> - Rename a Git branch.
  • git branch -r - Display a list of the remote branches in your Git repository.
  • git push <remote> --delete <remote-branch-name> - Delete a remote Git branch.
  • git push --set-upstream <remote> <branch> - Set an upstream branch. Running this command will push your local branch to the new remote branch.

Git Cherry Pick Commands



Git Commit Commands


  • git status - Display a list of files in your staging directory with accompanying file status.
  • git add - Stage file changes. Running this command with an associated file name will stage the file changes to your staging directory.
  • git commit - Save changes to your Git repository. Running this command with an associated file name will save the file changes to your repo.
  • git commit -a - Add all modified and deleted files in your working directory to the current commit.
  • git commit --amend - Amend a Git commit. Edit a Git commit message by adding a message in quotation marks after the command.
  • git commit -m - Add a Git commit message. Add your message in quotation marks following the command.

Git Rebase Commands


  • git rebase <target branch name> - Rebase your currently checked out branch onto a target branch. This rewrites a commit(s) from the source branch and applies it on the top of the target branch.
  • git rebase --continue - Proceed with a Git rebase after you have resolved a conflict between files.
  • git rebase --skip - Skip an action that results in a conflict to proceed with a Git rebase.
  • git rebase --abort - Cancel a Git rebase. Your branch will be back in the state it was before you started the rebase.
  • git rebase <target branch name> -i - Initiate interactive rebase from your currently checked out branch onto a target branch.

Git Stash Commands


  • git stash - Create a stash with local modifications and revert back to the head commit.
  • git stash list - Display a list of all stashes in your repository.
  • git stash show - View the content of your most recent stash. This will show your stashed changes as a diff between the stashed content and the commit from back when the stash was created.
  • git stash drop <stash> - Remove a stash from the list of stashes in your repository.
  • git stash pop <stash> - Apply a stash to the top of the current working tree and remove it from your list of stashes.
  • git stash apply <stash> - Apply a stash on top of the current working tree. The stash will not be removed from your list of stashes.
  • git stash clear - Remove all stashes from your repository.

Get updates when we publish new concepts by signing up for our newsletter!