Skip to content

Git for Smart Beginners

by Topper on August 19th, 2008

This post won’t get you into any technical details of git; it’s more of “philosophy of git.”

The first thing to understand about git is that it is totally distributed. The source control on your local machine is *the* source. You then push and pull to whatever other repositories you want. Sure: your team might use one central repository that you all push and pull from, but that doesn’t make it the way git is *designed* to work.

The second thing to understand is that everything in git is a branch. Sure, there’s a “master” branch by default, but that’s just convention. “master” is actually no more important than any other branch.

Now after what I just said, you might find this next one confusing. Branches are just labels in git. So the branch “master” is a collection of commits and whatever other branch you have is just another collection of commits. When you merge branches, you’re just combining those histories. So (unlike subversion) when you delete a branch that is merged into another branch: you do not lose any of your history.

Branching is soooo easy. Make a branch for everything. Want to try something out (even if it’s small): make a branch, try it, if it works merge it into whatever branch you’re working on.

Here are some resources:
svn -> git
git docs
github

Here’s a real quick romp through all the commands you’ll probably need.

  1. Setup an account at github
  2. create a test repository
  3. follow those initial steps that github gives you
  4. now cd into your newly created git repository
  5. type “git branch”
  6. you’ll notice that master has a little * next to it like “* master” that indicates that you are in the master branch
  7. type “git branch -a” now you’ll notice there’s also an origin/master now… orgin/master is a branch that is tracking the branch “master” at github you setup “origin” when you setup your repository initially
  8. type “git checkout -b my_new_branch”
  9. type “git branch -a” you’ll now notice that you are in the branch my_new_branch which is a branch off the master branch
  10. type “git push origin my_new_branch” – Yay! you just pushed a new branch up to github
  11. type “git checkout master” and then “git branch” – you’ll see you’re back in master
  12. type “git fetch” and you just pulled down all the changes (there won’t be any) from github
  13. type “git merge origin/master” and you just merged the remote changes into your local master

That’s most of the commands you’ll need.

Hope that helped.

One Comment
  1. Mike permalink

    This helps indeed. Signed up for a free GitHub account… Step 1 completed. Check.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS