Sunday, May 3, 2009

Become a Git Junkie

Lots of Perl projects have been switching over to Git lately, most of them from Subversion.

Unfortunately this means that many people are using Git as if it was Subversion, and consequentially they are missing out on a lot.

Here are a few pointers to help you get to know some of Git's more powerful features:

  1. Read Git for Computer Scientists, and if you want a more in depth followup, Git from the Bottom Up. These two articles will help you understand how Git works on the inside. Git's terminology will suddenly seem clear, and you'll easily understand how merges are represented, what git rebase does, and why Git does copy/move detection after the fact.
  2. Play around with low level commands. For instance, try creating a commit by hand by manipulating the index and using git commit-tree.
  3. Get comfortable with git rev-parse. Git has a very powerful syntax for specifying revisions, and this syntax is used in virtually every command.
  4. Knowing how to specify revisions accurately will let you back out of mistakes with confidence using git reset --hard and git reflog.
  5. Get to know git push's refspec syntax, and how to get it to do exactly what you want. Once you're fixing mistakes in history you occasionally need to use the --force flag, but git push is a little more flexible than that =).
  6. Start using git rebase --interactive and git commit --amend. These two commands help you create a clean history. No more git commit -m "oops, forgot that other file..."
  7. Explore some of Git's more esoteric features, like submodules, git fast-import & git fast-export, the hook system, git filter-branch, and the .git/info/grafts file. It's fun and useful to figure out how these features work even if you don't need to use them right now.

4 comments:

SamV said...
This comment has been removed by the author.
SamV said...

Real git users make their commits with: git hash-objects -w -t commit --stdin

Anonymous said...

"# Start using git rebase --interactive and git commit --amend. These two commands help you create a clean history. No more git commit -m "oops, forgot that other file...""

Thanks for the tip, I've just started using Github and have three or four of these commits already. I'm conscious of spamming those who are following my projects with garbage updates.

nothingmuch said...

Just one thing to keep in mind: be careful not to push and and then change things too often. Push --force is fine and dandy till someone has already pulled. Then they will probably get very confused.

Cheers =)