how to use a secondary github account from the terminal
how to use a secondary github account from the terminal
introduction
This has been a big headache for me for a long time. I want to use more than one github account. It is ridiculously difficult. For some reason none of of the various instructions I followed worked, until this one did. Links at bottom to various other resources on the same subject.
This is set up per-repo. More clever automated solutions exist, see links at bottom. But they never worked for me.
The instructions that finally cracked it for me: Quick Tip: How to Work with GitHub and Multiple Accounts
This is not comprehensive at explaining how to use github, git
or the terminal from scratch. It is just to fill in existing knowledge. Also I assume you do everything the same way I do. If you donβt like it feel free to return to the original tutorials.
Do it with an empty repo and make sure everything has gone correctly because if you screw it up itβs really not so easy to backtrack.
Note replace the emojis
π = your secondary username
π₯ = repo name
create a new ssh
key for use with new account in ~/ssh/id_ed25519-π
Β and add it to the keychain
add to ~/ssh/.config
:
Host github-π
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519-π
Create new repo locally:
β― mkdir π₯
β― cd π₯
β― git init
Initialized empty Git repository in π₯/.git/
Make a tiny nothing commit:
β― git commit -m "init git"
On branch main
Initial commit
nothing to commit (create/copy files and use "git add" to track)
Login to github and create π₯ repo there
- Be sure to create the
README.md
Sync local and remote:
β― git remote add origin git@github-π
:π
/π₯
β― git pull origin main
From github-π
:π
/π₯
* branch main -> FETCH_HEAD
β― ls
README.md
open the README.md
Β make some tiny change and save it.
β― nano README.md
edit your local π₯/git/config
Β to add (use your correct commit email)
[user]
name = π
email = 000000+π
@users.noreply.github.com
[pull]
rebase = false
[branch "main"]
remote = origin
merge = refs/heads/main
send local files to remote
β― git add README.md
β― git commit -m "change readme local"
β― git push origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 260 bytes | 260.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github-π
:π
/π₯
b2a484f..9ef3ae5 main -> main
troubleshooting
if you check your ID via ssh
, it will still say your main account:
β― ssh -T git@github.com
Hi CouldBeThis! You've successfully authenticated, but GitHub does not provide shell access.
If you are having problems, here is how to determine which file is being applied
β― git config --show-origin user.name
β― git config --show-origin user.email
other useful links
- Use multiple Git accounts from a single Linux machine
- git - Multiple GitHub accounts on the same computer? - Stack Overflow
- Configuration options | GitLab
- A Note on Misconfiguring my SSH Config When Setting Up Two Github Accounts | Matthew J. Clemente
-
c-alpha/gituser: Set the user id in a git working copy quickly when using user.useConfigOnly
- Modularizing your git config with conditional includes | Whisper of the Heartman
- Managing multiple Git profiles - DeepSource
- git config - Is it possible to have different Git configuration for different projects? - Stack Overflow
- Git Your Way: includeIf
- Basic Git Setup Β· (think)
- Git config with multiple identities and multiple repositories Β· GitHub
-
Longer more complicated instructions using Keychain authentitcation: How to set Git for multiple GitHub accounts - DEV
- Setting up multiple GitHub accounts, the nicer way
- microsoft/Git-Credential-Manager-Core - Secure, cross-platform Git credential storage with authentication to GitHub, Azure Repos, and other popular Git hosting services. (No gitlab atm.)
- poss useful: Lazy manβs guide: multiple GitHub HTTPS accounts on Windows
Using git with multiple profiles and GPG+SSH keys | markentier.tech