This is assuming that you already have a main git identity configured and a corresponding ssh key pair in ~/.ssh/
(on linux)
$ cd ~/.ssh/
$ ls
$ config id_rsa id_rsa.pub known_hosts
If you are not there yet, refer to this GitHub howto.
We also assume that you have second GitHub account with username seconduser
and email address [email protected]
.
Create a new ssh key pair
$ cd ~/.ssh/
$ ls
$ config id_rsa id_rsa.pub known_hosts
$ ssh-keygen -t rsa -C "[email protected]" -f id_rsa_seconduser
You now have a second key pair
$ ls
config id_rsa id_rsa_seconduser id_rsa_seconduser.pub id_rsa.pub known_hosts
Then, add the new private key to your ssh authentication agent
$ ssh-add ~/.ssh/id_rsa_seconduser
You can delete all cached keys
$ ssh-add -D
Finally, you can check your saved keys
$ ssh-add -l
Edit file ~/.ssh/config
and add
# first (default) account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# seconduser account
Host github.com-seconduser
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_seconduser
$ cd some-repo
$ git config user.name "seconduser"
$ git config user.email "[email protected]"
And edit the repo git config file .git/config
to change the remote server
...
[remote "origin"]
- url = [email protected]:seconduser/some-repo.git
+ url = [email protected]:parolepol/some-repo.git
...
clone your repo git clone [email protected]:activehacker/gfs.git gfs_jexchan
cd gfs_jexchan and modify git config
$ git config user.name "jexchan"
$ git config user.email "[email protected]"
$ git config user.name "activehacker"
$ git config user.email "[email protected]"
or you can have global git config $ git config --global user.name "jexchan" $ git config --global user.email "[email protected]"
then use normal flow to push your code
$ git add .
$ git commit -m "your comments"
$ git push
Another related article in Chinese