Skip to content

Instantly share code, notes, and snippets.

@mechanical-snail
Last active October 1, 2015 05:28
Show Gist options
  • Save mechanical-snail/1930235 to your computer and use it in GitHub Desktop.
Save mechanical-snail/1930235 to your computer and use it in GitHub Desktop.
gitconfig for managing multiple git identities
[user]
; No default user, lest you start a project as the wrong user.
; You have to specify your identity per-repository, using init-xxx or setuser-xxx.
; @@@@@ TODO: Should actually give an error when trying to commit before specifying an identity.
name = "@@@No user configured@@@"
email = "@@@No user configured@@@"
[alias]
;;;;;; init and user control
; Creates an empty repository with root commit
; "git remote add origin .." is to make relative paths in submodules work; see http://stackoverflow.com/questions/1974181/
z--init-root-commit = !git init && git commit -m 'root commit' --author 'nobody <nobody@localhost>' --allow-empty && git remote add origin ..
init-u0 = !git z--init-root-commit && git setuser-u0
init-u1 = !git z--init-root-commit && git setuser-u1
; sets user info for the current repository. Should be run immediately after init. Author info is not changed in existing commits.
setuser-u0 = !git config user.name 'Username 0' && git config user.email '[email protected]' && git whoami
setuser-u1 = !git config user.name 'Username 1' && git config user.email '[email protected]' && git whoami
;whoami = config --get-regexp 'user\\..*'
whoami = !bash -c 'echo \"$(git config --get user.name) <$(git config --get user.email)>\"'
@da-x
Copy link

da-x commented Apr 12, 2014

email = "(none)" would do the work of causing an error in commit if no per-local identity is configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment