NAME
ghmulti - Helps when using multiple Github accounts with SSH keys
SYNOPSIS
ghmulti [ -c GITHUB_URL [DIR] | -u [GITHUB_URL] ]
ghmulti --help | --version
DESCRIPTION
This script helps when using multiple Github accounts with SSH keys. First, you should read this gist https://gist.github.com/oanhnn/80a89405ab9023894df7 and follow the instructions.
Note: this script uses the git command line tool, so git must be installed and available via PATH
.
To use this script, you need to add information in file ~/.ssh/config by adding comments like this:
Host github-foo
# User: John Doe <jd@foomail.com>
HostName github.com
IdentityFile ~/.ssh/foo
IdentitiesOnly yes
Host github-bar
# User: Mr. Smith <somename@blahmail.org> <ignored@mail> IGNORED STUFF
HostName github.com
IdentityFile ~/.ssh/bar
IdentitiesOnly yes
Host github-baz
# User: <abc@blubb.eu>
HostName github.com
IdentityFile ~/.ssh/baz
IdentitiesOnly yes
The script looks for Host
names beginning with github-
. It assumes that the part after the hyphen is your username on github. E.g., in the example above the github usernames are foo
, bar
and baz
.
The next line must be a comment line beginning with User:
followed by an optional name (full name, may contain spaces) followed by an email address in angle brackets (a second email address and a string may follow, but they are ignored by this script). The script uses this data like this:
git config user.email EMAIL
git config user.name FULLNAME
If you did not specify a full name, the script uses your github user name instead.
These are the variants of how you can use the script:
Without any arguments
If you are in a git repo, the script sets the remote URL to use the SSH key and configures the email address and the username as described above. Otherwise the script terminates with an error state.
-c GITHUB_URL [DIR]
Checks whether the user name is in ~/.ssh/config. If this is not the case, the script aborts with an error message. Otherwise it works like
git clone
, but also configures the repo as described above.-u [GITHUB_URL]
Prints the github URL in the format needed to use your SSH keys. If
GITHUB_URL
is not specified, the script attempts to determine a URL viagit remote get-url origin
.With this option, the script does not an configuration.
Note: the options -c
and -u
are mutually exclusive!
SEE ALSO
App::ghmulti, Git::RemoteURL::Parse, GitHub::Config::SSH::UserData
Another solution: https://gist.github.com/harshith-21/37cb8b86396af15ddb3280f80e91801a
LICENSE AND COPYRIGHT
This software is copyright (c) 2025 by Klaus Rindfrey.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.