git switch vest

Original link: https://blog.est.im/2023/stdout-06

If you have multiple github, bitbucket, gitlab accounts and need to switch back and forth, then this method may be useful to you.

To use git, you need to configure a ~/.ssh/id_rsa , which is troublesome if you have multiple identities. The traditional method found on the Internet is to edit ~/.ssh/config and add a configuration similar to this:

 Host estgit HostName github.com Port 22 User git IdentityFile ~/.ssh/est_github IdentitiesOnly yes

It is not impossible to do this, but you have to change the host name when you enter the command. for example

git clone [email protected]:est/aether-pelican.git

you need to change to

git@estgit:est/aether-pelican.git

Of course, this is not the most painful. The most painful thing is that if you use git submodules , it becomes very troublesome for you to switch vests. Because others can’t parse things like git@estgit with your project.

I researched a hack, directly changing .git/config of the repo can achieve the same effect. for example

 [core] sshCommand = /usr/bin/ssh -o IdentitiesOnly=yes -i ~/.ssh/est_github -a [user] name = est email = ...@...

In this way, you can switch n ssh identity identities in different repo at will.

This article is transferred from: https://blog.est.im/2023/stdout-06
This site is only for collection, and the copyright belongs to the original author.