Bash script for switching the Git user easily.
Copy git-user
into any directory and make sure it is in the PATH
(and the executable flag is set).
git user add [email protected] "John DOE"
git user add [email protected] "John Doe"
# inside the Git repository
git user set [email protected]
# sets user.name to John DOE
# and user.email to [email protected]
If gum or fzf is installed, then the user can be selected interactively by using the cursor keys:
git user set
# displays the following prompt
Select user (current: John DOE <[email protected]>):
John Doe <[email protected]>
> John DOE <[email protected]>
Users are stored in the global Git configuration. Hence, no additional config file is required.
git config --get-regexp 'users\..*'
# prints
[email protected] John DOE
[email protected] [email protected]
[email protected] John Doe
[email protected] [email protected]
By default, the global Git configuration is stored in ${HOME}/.gitconfig
e.g.,
[core]
autocrlf = false
...
[users "[email protected]"]
name = John DOE
email = [email protected]
[users "[email protected]"]
name = John Doe
email = [email protected]
Incomplete list of similar tools (ordered by stars in descending order, as of January 2023):
- https://github.com/geongeorge/Git-User-Switch
- https://github.com/matsuyoshi30/gitsu
- https://github.com/joealba/gitswitch
- https://github.com/gesquive/git-user
- https://github.com/forthedamn/gitum
- https://github.com/WindomZ/gituser.js
- https://github.com/krnsk0/guser
- https://github.com/spenserblack/change-git-user
- https://github.com/WindomZ/gituser
- https://github.com/timo-cmd/glitter