GoGit is a cli tool to quickly switch between github profiles/accounts.
Currently only works with very specific SSH config
setup (see below).
This tool is under development and can cause corrupt files. Please use with caution!
Before overwriting a file (e.g. ~/.ssh/config
or ~/.gitconfig
), GoGit will make a copy of the previous file.
This file will have the same name as the original but with .bak
appended to the end.
For example .gitconfig
=> .gitconfig.bak
, these files can come in handy to restore the old file when a corrupt file is produced.
I found it annoying having 3 GitHub accounts at once and having to use special Host
values in my SSH config like this:
# Work account (default)
Host github.com
Hostname github.com
Port 22
User git
IdentityFile ~/.ssh/id_a
Host github.com-personal
Hostname github.com
Port 22
User git
IdentityFile ~/.ssh/id_b
Host github.com-other
Hostname github.com
Port 22
User git
IdentityFile ~/.ssh/id_b
And then I had to alter the remote url for each local repo to have the correct permissions to the remote repo:
git remote add origin [email protected]:username/repo.git
After not finding a nice solution for this problem, I figured I could build one as a side project.
To fix this issue I am building a cli too that can manage my git profiles/accounts for me.
When I arrive at work, I run 1 single command to switch to my work git account and everything is setup as it should.
When I get home, I just switch accounts again with 1 command.
- git
- Go 1.20 or up
After cloning the repo, you can build and move the binary bin/gogit
to a place in your PATH
.
I prefer to use /usr/local/bin/
Build binary
make build
Install on MacOS or Linux
Builds binary and moves it to /usr/local/bin/
make install
sudo make install # if you require root access for /usr/local/bin/
Add a new git account to the GoGit config with the following arguments:
name
:- custom name for profile
email
:- (optional) email of your git account
- default = current email in
~/.gitconfig
username
:- (optional) name of your git user
- default = current name in
~/.gitconfig
remote
:- (optional) custom remote name
- default =
github.com
Set the current active account.
GoGit will only change the Host
values in your SSH config.
For example: github.com-<name>
to github.com
and back.
All other settings will be left unchanged.
Create a blank GoGit config file
See the current active account
Remove a profile/account from GoGit, leaves your SSH config untouched.
Get a list of the current configured profiles/accounts with the arrow ->
indication the active one.
profiles:
-> home
- work
- other
GoGit currently requires you to have your SSH config file setup up in a specific way. This needs to be done manually for now.
See the problem section for an example structure of a working ~/.ssh/config
file.
Located at: ~/gogit.ini
[profiles]
first = true
second = false
[preferences]
# enable if you want to auto update your global git config user and email
set-git-user = false
[profile.a]
remote = github.com
username = User a
email = [email protected]
[profile.b]
remote = github.com
username = User b
email = [email protected]
- Setting
set-git-user
totrue
will make GoGit alter your~/.gitconfig
file - Each profile has unique settings
- Option to atuo add new block to ssh config on
gogit add
- Add
gogit remove
command to remove a profile/account - Add support for other git remotes
- Setting
git config --global
when activating account