87

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

17

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 :-)

13
[alias] 
    st = status
    ci = commit
    co = checkout
    w = whatchanged

[diff]  
    renamelimit = 0

[color] 
    diff = auto
    interactive = auto
    status = auto
    branch = auto
12
[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.

11
[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 \"$@\""
9

When using github.com this might be useful

[github]
    user = github username
    token = github API token
6
[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
5

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/
5

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
4

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
#
# 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
3

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.

3

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

0
[core]
    excludesfile = ~/.gitignore

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

and more.