Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

git resources

Manuals

Articles

Misc

Github

git-annex

Git Snippets

Config

~/.gitconfig is the global one, valid for all projects:

[user]
    email = john@example.net
    name  = John Doe
    signingkey 3AA5C34371567BD2
[alias]
    ci = commit -S
    co = checkout
    stat = status
    hist = log --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) %C(yellow)[%an]%C(reset) | %C(red)%s%C(reset) %C(blue)%d%C(reset)' --graph --date=short
[includeIf "gitdir:~/repos/job"]
    path = ~/repos/job/.gitconfig-job
  • user.signingkey is the ID of the PGP key to use when signing commits/tags, see e.g. Telling Git about your signing key
  • using aliases we can have shortcuts for git commands. With the above, git ci would be the same as git commit -S (initiate a signed commit – and yes, you also can use git ci -m '<commit-message>' with that alias)
  • git hist will give you a much prettier formatted git log
  • includeIf tells git to also look at the ini file specified by path in that block if you are in a git repo located below that gitdir

~/repos/job/.gitconfig-job overrides some settings specifically for „work projects” located below ~/repos/job:

[user]
    email = john.doe@example.com
    signingkey 42B317FD4BA89E7A

This ini file specifies settings which should differ for given repositories (see includeIf above). While you certainly want to have the same aliases everywhere, your „work projects” might need a different email address, for example. Or use a different PGP key to sign your commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.