Git: Common Tasks

As a git user I am no expert.

I don’t know if I’ll ever be, yet I use it every day.


I’m not alone — many people recognize the critical role version control plays in development work, but it’s challenging to find time to take yourself from a working knowledge to even a moderate expertise.


It’s something we can all work on. It would serve us well, since a working knowledge often has gaps, gaps which become a hassle in daily work life. Many times I’ve had to look up very straightforward tasks simply because I’d never learned to perform that task in git! And what I often find is that I am only one of many, many developers asking the same kinds of questions — and more often than not, the solution is a simple, one-line command!


With that in mind, I’ve put together a list of simple, common tasks that perhaps don’t come up as often as the standard “clone – fetch – merge – pull – add- commit – push” commands you use everyday. Hopefully, you’ll recognize something in this list and make your life a bit easierĀ  (or at least save you a google search next time).

Check your branch

git branch



git status

(the latter also gives you additional info).

List remote repos

git remote -v

Move to a previous commit (temporarily)

git checkout <commit>

You can find the commit id with git log.

Move to a previous commit (permanently)

git reset --hard <commit>

Oops! Wrong branch — switch my uncommitted changes to a new branch.

git checkout -b <new-branch-name>

Compare the changes to a file between commits

git diff HEAD~1 HEAD <file>

Replace the ‘1’ with the number of commits back you want to compare. Leave off the filename to see all files.

Remove cached files (e.g. previously committed files now in .gitignore)

git rm --cached

One thought on “Git: Common Tasks

  1. Pingback: A Few More Git Tips & Tricks | Et Cetera

Leave a Reply

Your email address will not be published. Required fields are marked *