一般来说,我们使用ssh clone <git仓库地址>就可以将项目克隆到本地。如果仓库地址是ssh协议地址,那么默认会使用当前用户环境的私钥去连接。
如果我们希望使用指定的私钥,又不想动当前用户环境的私钥,我们可以这么做:
1、初始化空版本库
2、添加远端地址
3、配置ssh命令,让命令带上指定私钥
4、拉取远端版本信息
5、切换到指定分支
以下是DEMO:
git init git remote add origin <git@xxx的ssh地址> git config core.sshCommand "ssh -i <指定私钥文件路径>" git fetch git checkout master