share
Stack OverflowWhat does your ~/.gitconfig contain?
[+92] [16] Rajkumar S
[2008-11-06 06:17:49]
[ git dotfiles ]
[ http://stackoverflow.com/questions/267761] [DELETED]

Hi,

I am looking to pimp up my ~/.gitconfig to make it really beautiful and take maximum advantage of capabilities git can offer. My current ~/.gitconfig is below, what more would you add? Have some nice ~/.gitconfig you want to share? Any recommendations for merge and diff tools in linux? Post away and let's build a nice ~/.gitconfig

[user]
        name = Rajkumar
        email = username@mydomain.com

[color]
        diff = auto
        status = auto
        branch = auto
        interactive = auto
        ui = true
        pager = true

[color "branch"]
        current = yellow reverse
        local = yellow
        remote = green

[color "diff"]
        meta = yellow bold
        frag = magenta bold
        old = red bold
        new = green bold

[color "status"]
        added = yellow
        changed = green
        untracked = cyan

[core]
        pager = less -FRSX
        whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol

[alias]
        co = checkout

Thanks!

raj

[+18] [2008-11-07 14:24:44] webmat

Great idea! Actually I have little to offer over these configs, except maybe this:

[core]
  excludesfile = /Users/mat/.gitignore

Make sure you use a complete path (i.e. not ~) for your global ignore file. This is especially useful when you create git repos extremely often, it just removes the need to create the same git ignores over and over.

Of course when other people are going to work on the project, you'll want to create a proper ignore file for the project :-)


Thanks dude. That was helpful! - johncblandii
(6) Git 1.6.5.5+ can use ~/whatever in core.excludesfile (and some other configuration variables). - Chris Johnsen
Awesome! Thanks for pointing it out, Chris :-) - webmat
1
[+13] [2008-11-06 07:49:46] ididak
[alias] 
    st = status
    ci = commit
    co = checkout
    w = whatchanged

[diff]  
    renamelimit = 0

[color] 
    diff = auto
    interactive = auto
    status = auto
    branch = auto

(2) What does the renamelimit do? I've looked at it in git docs but I still don't get it. - drozzy
(1) diff.renameLimit: The number of files to consider when performing the copy/rename detection; equivalent to the git diff option -l. kernel.org/pub/software/scm/git/docs/git-config.html - mmrobins
(1) st = status ci = commit co = checkout w = whatchanged - ewwwww - BlueRaja - Danny Pflughoeft
(2) These aliases are good for svn users - Casey Watson
+1 agree w/ Casey Watson. Coming from SVN these shortcuts have made the transition a lot easier! - pyrony
2
[+12] [2008-12-07 18:27:46] Scotty Allen
[apply]
  whitespace = fix

This will both warn you about some whitespace errors (such as trailing whitespace), as well as try and fix them for you.


3
[+12] [2010-07-08 10:21:27] Mikko Rantalainen
[rerere]
    enabled = true
[alias]
    # https://git.wiki.kernel.org/index.php/Aliases
    co = checkout
    st = status
    # usage example: git w -n5
    w = whatchanged
    # add all changed (but not new) files to stage (index):
    au = add -u
    # show conflicting merge in gitk:
    gitkconflict = !gitk --left-right HEAD...MERGE_HEAD
    # prune all tracking local branches that have been removed from remote:
    prune-all = !git remote | xargs -n 1 git remote prune
    # show full history in gitk (including "deleted" branches and stashes)
    history-all = !gitk --all $( git fsck | awk '/dangling commit/ {print $3}' )
    # show list of contributors in descending order by number of commits
    rank = shortlog -sn --no-merges
    # given a string for an author, try to figure out full name and email:
    whois = "!sh -c 'git log -i -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -"
    # given any git object, try to show it briefly
    whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
    # Search for a given string in all patches and print commit messages
    # example: search for any commit that adds or removes string "foobar"
    #     git searchcommits foobar
    # example: search commits for string "foobar" in directory src/lib
    #     git searchcommits foobar src/lib
    # example: search commits for "foobar", print full diff of commit with 1 line context
    #     git searchcommits foobar --pickaxe-all -U1 src/lib
    searchcommits = "!f() { query=\"$1\"; shift; git log -S\"$query\" \"$@\"; }; f \"$@\""

what is the "rerere" for? - mt3
(1) progit.org/2010/03/08/rerere.html it remembers manual conflict resolutions so you don't have to redo them later. - nornagon
you learn something new every day.... :) - mt3
4
[+9] [2009-02-19 10:48:39] x-way

When using github.com this might be useful

[github]
    user = github username
    token = github API token

5
[+6] [2009-03-15 16:02:46] community_owned
[user]
    name = prtksxna
    email = email@email.com

[branch "master"]
    remote = origin
    merge = refs/heads/master

[color]
    pager = true
    ui = true
    status = auto
    branch = auto

[alias]
    st = status
    ci = commit
    br = branch
    co = checkout
    df = diff
    lg = log
    pom = push origin master
[color "status"]
       added = yellow
       changed = green
       untracked = cyan

(2) I like the pom alias :) - leif81
6
[+5] [2009-02-27 21:49:51] Mark Thalman

Figuring out how to add a GUI external diff/merge tool was not easy so I'll include that bit from my ~/.gitconfig

Writing git-diff-driver.sh is left as an exercise for the reader :)

[diff]
    external = "/Users/mark/bin/git-diff-driver.sh"
[merge]
    tool = araxismerge
[mergetool "araxismerge"]
    cmd = "/usr/local/bin/compare -3 -merge -wait $LOCAL $BASE $REMOTE $MERGED"
    path = /usr/local/bin/

This is a killer-feature. --- opendiff for Mac users. - Masi
(2) What I don't like about FileMerge is you can't edit the file in the diff view. That is one of the reasons I bought Araxis Merge. - Mark Thalman
7
[+5] [2010-03-18 00:04:20] mipadi

Mine's not that exciting, but I do have some useful aliases:

[apply]
    whitespace = nowarn
[color]
    branch = auto
    diff = auto
    interactive = auto
    status = auto
[interactive]
    singlekey = true
[merge]
    tool = opendiff
[alias]
    br = branch
    ci = commit
    co = checkout
    sb = show-branch
    st = status
    ds = !git --no-pager diff --stat -M -w
    changes = log --oneline --reverse
    # fork = !sh -c 'git rev-list --boundary $1...$2 | grep ^- | cut -c2-'
    graph = log --graph --oneline --decorate
    info = config --list
    pop = !git stash apply && git stash clear
    staged = diff --cached
    summary = log --oneline
    tags = tag -n1 -l

8
[+4] [2010-04-13 02:59:51] orange80
#
# This is the config file, and
# a '#' or ';' character indicates
# a comment
#

[color]
    ui = auto

[user]
    name = xxxxxxxxxxxxxxxxx
    email = xxxxxxxxxxxxxxxx

[branch]
    autosetupmerge = true

[apply]
    whitespace = nowarn

[alias]
    st = status
    au = add -u .
    ci = commit
    ciam = commit --amend
    br = branch
    co = checkout
    df = diff
    lg = log
    lp = log -p
    lt = log --topo-order
    gl = log --graph
    # glp = log --graph --pretty=oneline --abbrev-commit
    glt = log --pretty=format:'%h : %s' --topo-order --graph
    rl = reflog
    sb = show-branch
    brm = branch --merged
    brnm = branch --no-merged
    rnc = revert --no-commit
    com = checkout master 
    hard = reset --hard
    me = merge --no-commit --no-ff
    ls = ls-files
    pu = pull
    cp = cherry-pick
    cpnx = cherry-pick --no-commit -x

9
[+4] [2010-03-18 00:00:38] mmrobins

A couple more .gitconfig options I've found useful.

[diff]
    renames = copy # makes the diff much shorter when moving or copying files
[commit]
    template = ~/work/developer/util_src/git/.gitcommittemplate

renames = copy is like passing the -C option to 'git diff', which detects when you move or copies files and only shows you the changes between the original instead of the whole file.

Where I work we like to have somewhat consistent commit messages that indicate the ticket number associated with the commit, who paired on and/or who reviewed the commit, so having a template is a good way to remind people to fill that in. The template comes up automatically if you commit without the -m option.


(4) hey, can you show us a sample template? Thanks! - Vijay Dev
10
[+3] [2010-02-02 07:43:51] Olivier

Here is also a pretty nifty configuration file: http://www.jukie.net/~bart/conf/gitconfig.

The file is linked from http://www.jukie.net/~bart/blog/pimping-out-git-log.


Links break; you should probably include the text of the config file. - Evan Kroske
11
[+3] [2010-06-30 23:38:15] jtolds

some aliases i have

    # thanks to zach wily, this is for pushing reviews to gerrit
    push-change = "!bash -c ' \
        local_ref=$(git symbolic-ref HEAD); \
        local_name=${local_ref##refs/heads/}; \
        remote=$(git config branch.\"$local_name\".remote || echo origin); \
        remote_ref=$(git config branch.\"$local_name\".merge); \
        remote_name=${remote_ref##refs/heads/}; \
        remote_review_ref=\"refs/for/$remote_name\"; \
        r=\"\"; \
        if [[ $0 != \"\" && $0 != \"bash\" ]]; then r=\"--reviewer=$0\"; fi; \
        if [[ $1 != \"\" ]]; then r=\"$r --reviewer=$1\"; fi; \
        if [[ $2 != \"\" ]]; then r=\"$r --reviewer=$2\"; fi; \
        if [[ $3 != \"\" ]]; then r=\"$r --reviewer=$3\"; fi; \
        if [[ $4 != \"\" ]]; then r=\"$r --reviewer=$4\"; fi; \
        git push --receive-pack=\"gerrit receive-pack $r\" $remote HEAD:$remote_review_ref'"

    # thanks to cody cutrer
    cherry-pick-merge = "!bash -c 'git cherry-pick -n -m 1 $0 && \
        git log -1 --pretty=%P $0 | cut -b 42- > .git/MERGE_HEAD && \
        git commit -v'"

    # other useful things
    remote-ref = "!bash -c ' \
        local_ref=$(git symbolic-ref HEAD); \
        local_name=${local_ref##refs/heads/}; \
        remote=$(git config branch.\"#local_name\".remote || echo origin); \
        remote_ref=$(git config branch.\"$local_name\".merge); \
        remote_name=${remote_ref##refs/heads/}; \
        echo remotes/$remote/$remote_name'"
    rebase-recent = !git rebase -i $(git remote-ref)

12
[+2] [2010-05-26 08:34:57] Amadeus
[core]
    editor = gvim -f
    pager = cat
[alias] 
    amend = commit --amend
    co = checkout
    d = diff
    dc = diff --cached
    ds = diff --stat
    dsc = diff --stat --cached
    l = log --pretty='tformat:%h %an (%ar): %s'
    ly = log --pretty='tformat:%h %an (%ar): %s' --since=yesterday
    s = status
    r = show --raw
    rank = shortlog -sn --no-merges
    w = whatchanged --reverse

(1) Similar to this, but with color: l = log --pretty='format:%C(3)%h%Creset %s %Cred%d%Creset' --graph - William Pursell
13
[+1] [2011-01-07 05:55:15] Sam Soffes
[user]
  name = Sam Soffes
  email = my email
[alias]
  lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
[color]
  diff = auto
  status = auto
  branch = auto
[core]
  excludesfile = ~/.gitignore
[apply]
  whitespace = nowarn
[merge]
  tool = kdiff3
[difftool]
  prompt = false

Notice I'm using kdiff3 [1] for my merge tool. It's a really sweet 3-way merge. Takes some getting used to, but it's super powerful. You should try it. opendiff is the default.

[1] http://kdiff3.sourceforge.net/

14
[+1] [2011-01-24 12:42:15] Vi
  1. Fixup/autosquash
  2. Signing key
  3. Memory limit for repacking
  4. Global excludes file
  5. rerere
  6. simple filter (clean up modification time from XML element)
  7. Wordwise diff alias
[user]
    name = ...
    email = ...
    signingkey = CD5B80FE1735A052
[gui]
    spellingdictionary = en
[alias]
    st = status
    co = checkout
    br = branch
    ci = commit
    a = add
    fixup = !sh -c 'git commit -m \"fixup! $(git log -1 --format='\\''%s'\\'' $@)\"' -
    squash = !sh -c 'git commit -m \"squash! $(git log -1 --format='\\''%s'\\'' $@)\"' -
    ri = rebase --interactive --autosquash
    wdiff = diff --color-words
[pack]
    windowMemory = 256m

[filter "gconf"]
    clean = sed 's/mtime=\"[0-9]*\"//g'
[rerere]
    enabled = true
    autoupdate = true
[color]
    ui = true
[core]
    excludesfile = /home/vi/.gitignore_global

Plus added colour and pager settings from the question.


15
[0] [2010-04-05 21:43:35] Kana Natsuno
[core]
    excludesfile = ~/.gitignore

[alias]
    lg = log --graph --pretty=oneline --abbrev-commit

and more [1].

[1] http://github.com/kana/config/blob/master/git/dot.gitconfig.in

16