The Subset of Git I Use


Git has a huge number of commands and I’ve only committed a small subset of them all to memory. These are the commands I use on a regular basis without needing to refer to the docs or man pages. They are roughly ordered by frequency of use.

This can serve as a beginner’s guide to a set of commands to be productive with Git, or perhaps a window into the idiosyncratic way another developer uses it.

  git status
Used constantly to see what branch I’m on and if there are staged or unstaged changes.

  git add --all
Used constantly to stage changes. This command stages everything, which is all I’ve ever needed to do.

  git commit
Used constantly to commit staged changes. I prefer to use my editor for commit messages.

  git commit --amend
Used constantly to touch up my last commit if I make changes that should logically be grouped with it.

  git checkout <branch>
Used constantly to switch branches.

  git diff
Used a few times a day to inspect unstaged changes.

  git diff --cached
Used a few times a day to inspect staged changes.

  git checkout -b <branch>
Used a few times a day to create a new branch from an existing one.

  git merge <branch>
Used a few times a day, either to fast-forward a branch or update a working branch that is already public.

  git log
Used a few times a day, usually either for a sense of recent changes or to look up a specific commit hash to work with.

  git fetch
Used a few times a day to update tracking branches.

  git push <remote branch> 
Used a few times a day to update a remote branch.

  git diff <branch>
Used a few times a day to compare my working branch with another.

  git reset --hard
Used once or twice a day, usually to discard small bits of experimental work.

  git rebase <branch>
Used once or twice a day to bring updates from one of the main branches into my working branch. I prefer this over git merge while working locally to reduce the number of merge commits cluttering the history, but could easily get by without it.

  git branch -u <tracking branch>
Used once or twice a day to start indicating a working branch’s progress as compared to a tracking branch.

  git branch -D <branch>
Used once or twice a day to clean up obsolete branches.

  git mv <filepath> <filepath>
Used a few times a week to move files while retaining their commit history.

  git clone <repository>
Used a few times a month to clone repositories.

  git remote <-v|add|set-url>
Used a few times a month to modify tracked repositories.

And that’s basically it. I will ocassionally use other more complicated commands like git filter-branch, but will probably need to refer to the docs to remember their specifics. There are also some simple commands I’m aware of but don’t tend to bother with much, like git rm (using git add --all makes it unnecessary), or git stash (I prefer to just make a temporary commit to come back to, it works and saves me from memorizing yet more commands).