People learning Git usually realize very soon that it can make a lot easier their daily development tasks and collaboration with other developers.
This is true even for people proficient with traditional version control systems (like SVN), that lack the advanced branching and merging functionalities typical of modern DVCSes.
You can be even more productive by setting up your client and environment to make it fit better your needs. Here are some tips, based on my configuration, hope you find them useful too!
Tweaking the configuration
Every Git repository has a configuration file called config located in the .git directory. Moreover there’s a global config file called .gitconfig and located in the user’s home directory.
Options specific to the each repository (eg. remotes and branches configuration) go in .git/config, while general options should be put in .gitconfig. For instance, I’ve put my name and email there:
[user] name = Domenico Rotiroti email = email@example.com
Git uses these informations to fill the author’s data every time I do a commit.
Configuration options can be read and modified by editing the files by hand or using the git config command. So I could set my name this way:
git config --global user.name Domenico Rotiroti
If you’re new to git I recommend that you read the git-config man page to see how many things you can configure!
A prettier output
One of the most used (and useful) git command is “diff”. If you add the --color option you will see that removals are printed in red, while additions in green.
@@ -1,6 +1,6 @@
$vcs = array ( “git”, “svn”, “bzr”, “hg” );
Nice, isnt’t it?
If you like it, you can make diff output colored text by default by setting the color.diff option:
git config --global color.diff auto
Diff has another nice option, called --color-words, that will show the changed words in a line side-by-side instead of outputting two lines. Personally, I prefer the traditional format, but if you don’t agree I suggest you to add an alias:
git config --global alias.wdiff 'diff --color-words'
With this alias in place, just run ‘git wdiff’ to get a word-colored diff.
With aliases you can do a lot of nice things, for instance I found useful to a have an alias with my favorite options for the log command:
git config --global alias.oneline 'log --oneline --decorate'
We’ve seen that new commands can be added to git using aliases. This is not the only way!
The command line client git acts as a command wrapper: whenever you run “git somecommand” it looks for git-somecommand in the path and executes it passing by all the parameters.
Adding new functionalities is really simple, indeed someone already did it!
I recommend you to take a look at visionmedia‘s git-extras here http://github.com/visionmedia/git-extras, it adds several useful commands.
Of course I couldn’t forget to mention our repos-tools, that could make you save time when working with multiple repositories.
If your repos are on GitHub, you can fork, watch, list issues and more from the command line.
For today, that’s it! Got tips to share? Write us a comment while they’re open.