Top Tips and Handy Hacks for Git
Posted by Alec The Geek on 3 December 2009
Last updated 7/June/2012
I don’t think any of these ideas are originally mine and I apologise that I do no longer have the correct information to credit the appropriate people.
This is my place to put some of the tips and tricks I come across when using Git. There are of course lots of other places on the inter tubes that provide better tips. These are just mine and I’ll update this over time
- Before making the first commit to a repo check the email address (
git config --get user.email) and if needed set the email address to different value on the repo by omitting the--globaloption to the commandgit config user.email myhandle@cool.com) - Set up a global .gitignore file to be used by all repos
- Create a file ~/.gitignore with some useful exclusions (e.g. the backup files for your editor or .DS_Store on OS/X)
- run the command
git config --global core.excludesfile ~/.gitignore
- Help Window users and yourself by running
git config --global core.autocrlf input(see GitHub help), but beware of lots of apparent line ending changes after setting this , these are benign. - Keep a copy of this handy picture around as an aide-memoir

- Get a public Git repo account. My favourite is GitHub, other options include Gitorious and BitBucket
- Would you like the git help text to appear in a browser. Run
git config --global help.format web. N.B. Needs the html version of the Git documents installed. Don’t like the default browser? Rungit config --global web.browser chromium - Using
httpsinstead ofgitas your transport protocol? You can now use various helper programs to cache your https credentials. The GitHub setup help page has details for each platform
Using Git from Bash?
- Add the following to your ~/.bashrc file NB file locations correct for Ubuntu Linux 9.10 and Cygwin
# enable git programmable completion features if [ -f /etc/bash_completion.d/git ]; then . /etc/bash_completion.d/git PS1='\[\e]0;\u@\h: a\]${debian_chroot:+($debian_chroot)}\u@\h:\w \$(__git_ps1 \' (%s)\')$' fiOn Cygwin try
PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '. If you cannot locate the bash completions file on your system then you can get a copy from the Git source tree - If you prefer to use gvim for your commit messages then add the following to .bashrc (NB You c set this in ~/.gitconfig if you prefer
git config --global core.editor=....)export GIT_EDITOR="/usr/bin/gvim --nofork". See below for more Vim tips
Using Git on Ubuntu GNU/Linux? Ubuntu users should add the Git PPA to their sources so that they get Git updates and new releases.
KDiff3 is available for Windows (handy for diffs and merges)
Using Git from Vim? — see the Vim Git tips
5 Responses to “Top Tips and Handy Hacks for Git”
Sorry, the comment form is closed at this time.

![[FSF Associate Member]](http://static.fsf.org/nosvn/associate/fsf-10505.png)
nothingmuch said
I recommend against a global gitignore. I did this way back when I started using Git and it seemed like a good idea at the time, but then people started collaborating on some of those projects and did not have the same ignore rules as I did, leading to lots of confusion.
Alec said
I agree it can be a problem. I am selective about what goes into my global ignore file. i.e. they are files that are specific to to my environment (see the examples above).
I still have a project .gitignore for the files that the project ignores (e.g. in one project I ignored the .eps files created by Dia, that was project specific)
Sam Watkins said
my .git/info/exclude excludes quite a lot, especially all dotfiles:
\.*
_*
*~*
CVS
RCS
*.[oa]
*.exe
*.so
*.dll
I use hidden dotfiles and directories to hide stuff that I don’t want to actually commit to git. If I want it to be visible but not commit the actual data, I use a symlink to a dotfile, like foo -> .foo
In my case almost all of my git usage is via a program I wrote with a friend called “arcs”. This automates commit/pull/push in a single invocation, for me, using git for history and syncing is as simple as typing `arcs`.
Sam Watkins said
Also, the webserver I’m writing doesn’t serve dotfiles, for much the same reason.
Alec said
Sam,
Using your approach how do you commit dotfiles that you want in the repo?