On ~/.gitconfig
[user]
name = personal
email = [email protected]
[includeIF "gitdir:~/workspace/"]
path = ~/work.gitconfig
Then on ~/work.gitconfig [user]
name = workname
email = [email protected]
[1] https://git-scm.com/docs/git-config#_conditional_includesIf you don't use this in any nested envrc files, the settings don't carry over which means your git settings are not maintained. It is kind of an escape hatch as the parent files are not verified in the same way normal envrc files are, but I have found the trade off to be worth it
$ git whoami
GIT_COMMITTER_IDENT=Mel Smith <[email protected]>
GIT_AUTHOR_IDENT=Mel Smith <[email protected]>
`whoami` can be implemented via a simple alias: git config --global alias.whoami = "! git var -l | grep '^GIT_.*_IDENT'"But: does this edit a file that can appear in .gitignore or are you uploading this to affect all your collaborators?
Why `; :` at the end?
$ git config alias.foo '! echo "$1";'
$ git foo bar
bar
echo "$1";: bar: command not found
Whereas if I end with `; :` then it works as expected: $ git config alias.foo '! echo "$1"; :'
$ git foo bar
bar
It seems to execute the last argument (`bar`) as a command without the `:` at the end, and I don't have a `bar` command on my PATH so it angrily fails with exit code 127. If it instead executes `:` however, that will make it happily exit with 0.It seems to be a Git alias quirk, but I may be incorrect here.
argv_array_pushf(out, "%s \"$@\"", argv[0]);
So, you can have aliases like `!grep foobar` to automatically accept arguments or aliases like yours that use arguments explicitly.I've done aliases like `!bash -c 'foo $1' sh` before, but on seeing yours, I see that it was unnecessary to re-wrap with bash.
[1] https://github.com/git/git/blob/e31aba42fb12bdeb0f850829e008...
git config alias.foo '!f() { actual command goes here }; f'
as that will pass all the args to the shell function. But if git is already setting it up so the args work then suffixing the alias with ";:" seems simpler.Being able to use $1/$2/etc directly might be a relatively new development.
EDIT: Or maybe not. This might have been doable since 2010:
https://github.com/git/git/commit/8dba1e634af1d973a47fca616a...