请稍侯

不同的仓库使用不同的github账号提交

04 June 2022

不同的仓库使用不同的github账号提交

配置仓库

git config --add --local core.sshCommand 'ssh -i <<<PATH_TO_SSH_KEY>>>'

In some cases this doesn’t work because ssh_config overriding the command, in this case try ssh -i ~/.ssh/[insert_your_keyname] -F /dev/null to not use the ssh_config. such as below:

git config --local core.sshCommand "ssh -i ~/.ssh/id_ed25519_lothing -o IdentitiesOnly=yes -F /dev/null"

Refer:https://stackoverflow.com/questions/7927750/specify-an-ssh-key-for-git-push-for-a-given-domain

To use a specific key on the fly:

GIT_SSH_COMMAND='ssh -i $HOME/.ssh/id_ed25519 -o IdentitiesOnly=yes -F /dev/null' git push origin master

Explanation:

  • local ENV var before doing the push
  • -i specifies key
  • -F forces an empty config so your global one doesn’t overwrite this temporary command