Git for ugly and stupid people; a git tutorial for subversion users

Previous Section – Tracking Branches

Pulling

Pulling is analogous to pushing but the data flow is the other way around. This is where you would take changes that have happened on the remote repo and introduce them to your local repo. The command to do this is git pull. It is actually an aggregate command in that it calls several other commands in sequence but it is a handy and reliable tool. Essentially git pull will do two things:

  • Update all of the remote tracking branches for the remote repo you are pulling from
  • Examine the branch you currently have checked out and if it has a remote tracking branch, merge in the remote tracking branch

The second point is fairly obvious and the resultant behaviour is what you might expect from svn update, the first part however isn’t necessarily obvious and happens behind the scenes. You will often notice that git is updating a lot of remote tracking branches that you aren’t working on when you do a git pull. This is fine, dont be alarmed! It sometimes looks like git is updating the wrong branch or has merged a different branch into yours, but it is just updating the tracking branches in order that the repo stay as up to date as possible.

As we’ve learned, if you check out a branch called ‘bigfeature’ then git will create a local branch based off the remote-tracking branch. If you then leave this branch for several weeks and work on something else then when you come to next work on bigfeature you might notice git telling you that you are ‘behind’ by several commits. All it is doing is comparing your local branch with the remote tracking branch. If there have been a lot of commits to the bigfeature branch by other people during the last few weeks then git wont have updated your local branch because you havent had it checked out. The graph would look like this:

If git is telling you you are behind then a git pull is all that is required to fix it. After a git pull in the above case your local branch pointer would just be fast-forwarded along to meet the remote tracking branch.

Summary

So the in summary your general git workflow will look something like this:

  • clone a repo from a remote source (usually github)
  • create a new branch or checkout an existing one
  • do some work
  • make one or many commits
  • during your work you can pull updates from the remote repo
  • when your work is ready, push it to the remote repo

References

http://eagain.net/articles/git-for-computer-scientists/ – Excellent references that explains how git works under the hood.
http://www.eecs.harvard.edu/~cduan/technical/git/ – Decent tutorial that takes you through most of the concepts involved with git.
http://gitref.org/ – Has quite a comprehensive guide to all the git commands and how to use them in practice

Advertisement

8 thoughts on “Git for ugly and stupid people; a git tutorial for subversion users

  1. Zsolt Almasi says:

    Focused, concise, just enough theory to understand how git works, just enough examples to understand the theory, meaningful illustrations and the author’s real life experience makes this article a great source for those wanting to switch quickly from svn to git. Saved me many hour of search and reading. Thank you !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s