by geongeorgek on 11/12/20, 12:59 PM with 57 comments
by varl on 11/12/20, 2:35 PM
git config --global --unset user.name
git config --global --unset user.email
git config --global --unset user.signingkey
git config --global user.useConfigOnly true
git config --global user.<id>.name "<name>"
git config --global user.<id>.email "<email>"
git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git config user.email "$(git config user.$1.email)"; :'
So given that I have created two users, e.g. personal and work I run: git identity work
in repos that need the work name/e-mail, and git identity personal
in the ones that are private.by pavlo on 11/12/20, 1:55 PM
What I have been doing by hand for some time is putting code for different customers in different directories and having a conditional in `~/.gitconfig` to determine what config applies there:
[includeIf "gitdir:~/projects-private/**"]
path = ./.gitconfig-private
[includeIf "gitdir:~/projects-client/**"]
path = ./.gitconfig-work
Then in .gitconfig-private or .gitconfig-work I have all the usual gitconfig settings that apply, for example the [user] section...Switching to the right directory thus automatically changes the settings.
by Foxboron on 11/12/20, 1:50 PM
by oefrha on 11/12/20, 2:03 PM
#!/usr/bin/env zsh
case $1 in
foo)
git config user.name 'John Doe'
git config user.email john@example.com
git config user.signingKey 0xFFFFFFFF
;;
bar)
git config user.name 'Jane Doe'
git config user.email jane@example.com
git config user.signingKey 0xEEEEEEEE
;;
baz)
git config user.name 'My Dog'
git config user.email dog@example.com
git config user.signingKey 0xDDDDDDDD
;;
*)
echo "usage: git-user foo|bar|baz" >&2
exit 1
;;
esac
Done.Btw probably want to add signingKey support.
by archseer on 11/12/20, 1:54 PM
by mr-karan on 11/12/20, 4:59 PM
by gurjeet on 11/14/20, 6:59 AM
[user]
name = Gurjeet Singh
# Tell Git to _not_ guess my name and email based on `whoami` and `hostname`
useConfigOnly = true
With this in place, whenever I try to commit for the first time in a repository, Git prompts me *** Please tell me who you are.*
I then add an email address to the repo-local config based on whether it's work or personal project. git config user.email me@example.com
by miguelmota on 11/12/20, 5:37 PM
by enriquto on 11/12/20, 2:24 PM
by 29athrowaway on 11/12/20, 7:29 PM
For my work repo I configure the repo to use my work identity. For my personal repos I use my personal identity.
I do not need to switch identities when using the same repo.
Doing this, you only setup your identity once per repo not every time, which is safer/less error prone. i.e.: you wont leak your work email on github by accident.
by KuiN on 11/12/20, 3:58 PM
by SparkyMcUnicorn on 11/12/20, 3:36 PM
const store = require("data-store")({ path: process.cwd() + "/data.json" });
I think a `git-user-data.json` file in a centralized location makes far more sense.by geongeorgek on 11/12/20, 1:01 PM
So I made this as a sugar for git config user.email whatever@gmail.com
by zachrip on 11/12/20, 2:03 PM
by Icyphox on 11/12/20, 2:06 PM