Gitting Used to Git
Friday, June 6th, 2008 by Andrew MooreI have been using git a lot more efficiently recently, and I want to share some of the more advanced things that may help you get used to using git, too.
First, it helps me a lot to have some things in color. I have found these four config changes to make it a lot easier to scan git output quickly. The “diff” one is especially handy.
- git config –global color.branch auto
- git config –global color.status auto
- git config –global color.diff auto
- git config –global color.interactive auto
Second, I have found “git add –interactive” to be pretty useful. If you have changed several files and only want to commit some of them, this will present a menu-driven interface to let you pick the files to add. Even better, if you have edited a file in two places and only want to include one “chunk” in your commit, this lets you specify that. It’s great if you have added some debug code at the top or bottom that you don’t want to commit.
Next, I’ve been using git rebase –interactive” to be able to re-order and combine my patches to make them more readable. If you have a long sting of small commits that you want to organize better, you can run “git rebase –interactive HEAD~20″. This will open an editor with the last 20 commits in it. You can reorder the lines to reorder the commits. You can also “squash” the lines to merge commits together. This will help you make more readable sets of commits.
Finally, if you have a commit that you want to split up, use “git rebase –interactive” to “edit” it. Then, “git reset HEAD^” to put yourself “back in time” to that spot. Then, you an choose only a subset of the files or patches to commit, commit them, and then optionally commit the rest.
For more help on using git, I have really found the gitcasts to be a tremendous help.
Some of these features require a newish version of git, so if yours doesn’t seem to be working like this, I recommend an upgrade.
git ‘er done!
