Skip to content

Automatically set git config properties in local repository based on remote URL

License

Notifications You must be signed in to change notification settings

alex-shpak/gitname

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gitname

Simple tool to set user.name and user.email or other properties in local git repository based on remote URL.

License: MIT Go Report Card

Use case

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.

Install

Homebrew

$ brew tap alex-shpak/gitname http://github.com/alex-shpak/gitname
$ brew install gitname

Pre-compiled Binaries

You can download binary for your platform directly from releases page.

Install from sources

$ go get -u github.com/alex-shpak/gitname
$ go install github.com/alex-shpak/gitname

Configure

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]

Run

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

Unset globally configured 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

About

Automatically set git config properties in local repository based on remote URL

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published