中央存储库必须设置在一个新的服务器上,所以我在本地回购上创建了一个新的远程存储库,并将其推送到该服务器上。
但现在当我做git拉,它声称我是最新的。这是错误的——它告诉我的是旧的远程分支,而不是新分支,我知道新分支实际上有新的提交要获取。
如何更改本地分支以跟踪不同的远程?
我可以在git配置文件中看到这一点,但我不想把事情搞砸。
[branch "master"]
remote = oldserver
merge = refs/heads/master
中央存储库必须设置在一个新的服务器上,所以我在本地回购上创建了一个新的远程存储库,并将其推送到该服务器上。
但现在当我做git拉,它声称我是最新的。这是错误的——它告诉我的是旧的远程分支,而不是新分支,我知道新分支实际上有新的提交要获取。
如何更改本地分支以跟踪不同的远程?
我可以在git配置文件中看到这一点,但我不想把事情搞砸。
[branch "master"]
remote = oldserver
merge = refs/heads/master
当前回答
根据我从最新的git文档中了解到的内容,概要如下:
git branch -u upstream-branch local-branch
git branch --set-upstream-to=upstream-branch local-branch
这种用法似乎与urschrei的回答有点不同,因为在他的简介中是:
git branch local-branch -u upstream-branch
git branch local-branch --set-upstream-to=upstream-branch
我猜他们又修改了文件?
其他回答
根据git文档,最好的方法是:
确保实际的起始路径:
Git remote -v
然后使用以下命令进行更改:
Git远程set-url源
其中URL -repository与我们从clone选项中获得的URL相同。
在最新的git 2.7.4版本中,
Git checkout branch_name #要更改跟踪分支的分支名称
Git分支——set-upstream-to=upstream/tracking_branch_name #upstream -远程名称
使用git v1.8.0或更高版本:
git branch branch_name --set-upstream-to your_new_remote/branch_name
或者你可以使用-u开关
git branch branch_name -u your_new_remote/branch_name
使用git v1.7.12或更早版本
git branch --set-upstream branch_name your_new_remote/branch_name
最简单的方法是简单地推到新的分支:
Git push -u origin branch/name
根据我从最新的git文档中了解到的内容,概要如下:
git branch -u upstream-branch local-branch
git branch --set-upstream-to=upstream-branch local-branch
这种用法似乎与urschrei的回答有点不同,因为在他的简介中是:
git branch local-branch -u upstream-branch
git branch local-branch --set-upstream-to=upstream-branch
我猜他们又修改了文件?