[英]Changing Git remote URL updates fetch but not push
I am attempting to change the remote URL of my origin branch in Git.我试图在 Git 中更改我的源分支的远程 URL。 All I want to change is the SSH port.
我想更改的只是 SSH 端口。 First, listing my remote origins gives me this:
首先,列出我的远程来源给了我这个:
git remote -v
origin user@example.com:package/name.git (fetch)
origin user@example.com:package/name.git (push)
Then, I run the set-url
command to change my origin URL:然后,我运行
set-url
命令来更改我的原始 URL:
git remote set-url origin ssh://user@example.com:XX/package/name.git (XX is my port #)
Now, I can fetch without issue, but pushing my branch to origin doesn't work, because the push URL didn't change.现在,我可以毫无问题地获取,但是将我的分支推送到原点不起作用,因为推送 URL 没有改变。 Listing my remotes again I get this:
再次列出我的遥控器,我得到了这个:
git remote -v
origin ssh://user@example.com:XX/package/name.git (fetch)
origin user@example.com:package/name.git (push)
Why did my set-url
command only change the fetch URL?为什么我的
set-url
命令只更改了获取 URL?
From git-remote
manual: 从
git-remote
手册:
set-url
Changes URL remote points to. Sets first URL remote points to matching regex <oldurl> (first URL if no <oldurl> is given) to <newurl>. If <oldurl> doesn’t match any URL,
error occurs and nothing is changed.
With --push, push URLs are manipulated instead of fetch URLs.
So you should additionally execute: 所以你应该另外执行:
git remote set-url --push origin ssh://user@example.com:XX/package/name.git
As long as the config file for the repo in question contains an entry for the push URL, set-url
will only update the fetch URL by default.只要有问题的 repo 的配置文件包含推送 URL 的条目,默认情况下
set-url
只会更新获取 URL。
[remote "origin"]
url = fetch.git
fetch = ...
pushurl = push.git
As the answer of running.t explains, you can use set-url --push
to change this entry.正如 running.t 的答案所解释的,您可以使用
set-url --push
来更改此条目。 However, you will have to keep doing this every time the URL changes.但是,每次 URL 更改时,您都必须继续执行此操作。
To restore the default behavior of set-url
(which changes both URLs at once), just delete the entry from the config.要恢复
set-url
的默认行为(同时更改两个 URL),只需从配置中删除该条目即可。 Or delete it using set-url --delete
:或者使用
set-url --delete
删除它:
git remote set-url --delete --push origin push.git
As for why a repository would ever contain a separate push url without you adding it: Some git clients like Sourcetree "helpfully" do this.至于为什么一个存储库会在没有你添加的情况下包含一个单独的推送 url:像 Sourcetree 这样的一些 git 客户端“有帮助”地做到了这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.