git - 更改 Git 远程 URL 更新获取但不推送

标签 git ssh

我正试图在 Git 中更改我的原始分支的远程 URL。我只想更改 SSH 端口。首先,列出我的远程来源给我这个:

git remote -v


origin  user@example.com:package/name.git (fetch)
origin  user@example.com:package/name.git (push)

然后,我运行 set-url 命令来更改我的原始 URL:

git remote set-url origin ssh://user@example.com:XX/package/name.git    (XX is my port #)

现在,我可以毫无问题地进行抓取,但是将我的分支推送到原点是行不通的,因为推送 URL 没有改变。再次列出我的 Remote 我得到这个:

git remote -v


origin  ssh://user@example.com:XX/package/name.git (fetch)
origin  user@example.com:package/name.git (push)

为什么我的 set-url 命令只更改了获取 URL?

最佳答案

来自 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.

所以你应该另外执行:

git remote set-url --push origin ssh://user@example.com:XX/package/name.git

关于git - 更改 Git 远程 URL 更新获取但不推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41876631/

相关文章:

linux - Ubuntu - .ssh 文件夹存在但我看不到它?只能通过终端

ssh - 通过 Tor 网络访问 ssh 客户端

git - 为什么 hudson / Jenkins 试图做出 promise ?

git - 将 git 更改 pull 入尚未 checkout 的分支

git - 使用另一个本地存储库更新本地 Git 存储库

php - 当解释器位于非标准位置时,如何解决 "bad interpreter"错误?

macos - 在 Mac Bash 中显示 git 分支和状态

xcode - 为什么更新到 OSX 10.10 后无法运行 git 命令?

bash - 远程获取在后台启动的作业的 pid

windows - 隐藏用户输入