不同的默认远程(跟踪分支)用于git pull和git push(Different default remote (tracking branch) for git pull and git pus

编程入门 行业动态 更新时间:2024-10-25 08:21:51
不同的默认远程(跟踪分支)用于git pull和git push(Different default remote (tracking branch) for git pull and git push)

有没有办法设置git仓库,所以git pull默认为一个remote, git push默认为另一个? 我知道我可以通过更改.git/config分支部分中的remote变量的值来设置两者 ,但是如何分别对每个方向进行设置?

Is there a way to set up a git repository, so that git pull defaults to one remote and git push defaults to another? I know I can set both by changing the value of the remote variable in branch section of .git/config, but how to do it for each direction separately?

最满意答案

对于Git 1.6.4及更高版本, remote.<name>.pushurl使用git config设置remote.<name>.pushurl 。

人们可能会使用这种方式使用只读https:协议来拉,并使用基于ssh的协议。


说origin的url( remote.origin.url )是https://git.example.com/some/repo.git 。 它是只读的,但您可以通过基于ssh的“URL” git@git.example.com:some/repo.git进行写入访问git@git.example.com:some/repo.git 。 运行以下命令来实现基于ssh的协议:

git config remote.origin.pushurl git@git.example.com:some/repo.git

For Git 1.6.4 and later, set remote.<name>.pushurl with git config.

One might use this to pull using the read-only https: protocol and push using an ssh-based protocol.


Say origin's url (remote.origin.url) is https://git.example.com/some/repo.git. It is read-only, but you have write access through the ssh-based ‘URL’ git@git.example.com:some/repo.git. Run the following command to effect pushing over the ssh-based protocol:

git config remote.origin.pushurl git@git.example.com:some/repo.git

更多推荐

本文发布于:2023-04-28 00:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分支   pull   git   push   branch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!