Alec the Geek

Reflections on software and related things from an older geek

  • Twitter Ramplings

  • My Bookmarks

  • RSS Alec’s GitHub

    • An error has occurred; the feed is probably down. Try again later.

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

  1. 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 --global option to the command git config user.email myhandle@cool.com)
  2. Set up a global .gitignore file to be used by all repos
    1. Create a file ~/.gitignore with some useful exclusions (e.g. the backup files for your editor or .DS_Store on OS/X)
    2. run the command git config --global core.excludesfile ~/.gitignore
  3. 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.
  4. Keep a copy of this handy picture around as an aide-memoirGit data transport commands
  5. Get a public Git repo account. My favourite is GitHub, other options include Gitorious and BitBucket
  6. 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? Run git config --global web.browser chromium
  7. Using https instead of git as 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?

  1. 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)\')$'
    fi
    

    On 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

  2. 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

About these ads

5 Responses to “Top Tips and Handy Hacks for Git”

  1. 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)

      • 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`.

      • Also, the webserver I’m writing doesn’t serve dotfiles, for much the same reason.

  2. Alec said

    Sam,

    Using your approach how do you commit dotfiles that you want in the repo?

Sorry, the comment form is closed at this time.

 
Follow

Get every new post delivered to your Inbox.

Join 272 other followers

%d bloggers like this: