Simple tool to set user.name
and user.email
or other properties in local git repository based on remote URL.
It is common to have multiple git repositories and platforms to work with. For example you might contribute OSS at github.com
and have private organisation github.com/private-organization
at your work, also some repositories at gitlab.com
. So then you might want to use different email and/or config for these repositories.
Here is where this tool useful. When you run gitname
, it will set local config in repository according to git remote. More specific URL has higher priority. See configuration for example.
$ brew tap alex-shpak/gitname http://github.com/alex-shpak/gitname
$ brew install gitname
You can download binary for your platform directly from releases page.
$ go get -u github.com/alex-shpak/gitname
$ go install github.com/alex-shpak/gitname
Add these lines to .gitconfig
file into your home directory, modify where needed. You can use other global git config files as well.
[user "github.com"]
name = Alex Shpak
email = [email protected]
[user "github.com/private-organization"]
name = Alexander Shpak
email = [email protected]
signingKey = xxx
[user "gitlab.com"]
name = Alex Shpak
email = [email protected]
Navigate to target git repository and run gitname
:
~/Projects/gitname » gitname
2019/10/11 21:14:54 Committing as Alex Shpak <[email protected]>
You can set specific section by passing name of section as argument: gitname github.com
, this comes useful when there is no remote yet.
You can also create handy alias.
$ git config --global alias.name '!gitname'
$ git name
Optionally run below commands to unset globally configured name and email and prevent Git from guessing them in newly cloned repositories.
$ git config --global user.name ""
$ git config --global user.email ""
$ git config --global user.useConfigOnly true