简体   繁体   English

通过ssh git克隆,推送https

[英]Git clone over ssh, push over https

I have a set of private Git repos in BitBucket. 我在BitBucket中有一套私人Git回购。 I want to clone them through SSH so that the cloning can be automated without asking for a password. 我想通过SSH克隆它们,以便克隆可以自动化而无需输入密码。 However, I want to push over HTTPS because I want to push with a different user name. 但是,我想推送HTTPS,因为我想推送一个不同的用户名。

The PC is a common PC, and I want to distinguish who pushes changes but I do not care about who clone them. PC是一个普通的PC,我想区分是谁推动了改变,但我不关心谁克隆它们。

Is there any way to do this? 有没有办法做到这一点? Thanks! 谢谢!

You can use two or more different remotes for that. 您可以使用两个或更多不同的遥控器。 By default, when you clone a remote repository, the remote origin is automatically created for you. 默认情况下,克隆远程存储库时,会自动为您创建远程origin But you can specify a different repository on the git command line each time literally like eg 但是你可以在git命令行上指定一个不同的存储库,每次都像字面意思一样

git push https://git-server/myrepo.git branch

but it is much more convenient to add them as named remotes if you plan to use them more than once. 但如果您计划多次使用它们,则将它们添加为命名遥控器会更方便。 Here is a more complete example transcript: 这是一个更完整的示例脚本:

git clone ssh://user1@git-server/myrepo.git
cd myrepo
git remote add push https://git-server/myrepo.git

Then you can git fetch origin or git pull to update the local checkout, and you can push with eg git push push branch (Note that the second push here is the name of the remote). 然后你可以git fetch origingit pull来更新本地签出,你可以使用例如git push push branch (请注意,这里的第二个push是远程的名称)。 This way, you can also specify a different ssh remote with a different user: 这样,您还可以使用其他用户指定不同的ssh远程:

git remote add push2 ssh://user2@git-server/myrepo.git

Then you can do git push push2 branch in order to push via ssh as a different user. 然后你可以做git push push2 branch ,以便通过ssh作为不同的用户进行推送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM