中央存储库必须设置在一个新的服务器上,所以我在本地回购上创建了一个新的远程存储库,并将其推送到该服务器上。
但现在当我做git拉,它声称我是最新的。这是错误的——它告诉我的是旧的远程分支,而不是新分支,我知道新分支实际上有新的提交要获取。
如何更改本地分支以跟踪不同的远程?
我可以在git配置文件中看到这一点,但我不想把事情搞砸。
[branch "master"]
remote = oldserver
merge = refs/heads/master
中央存储库必须设置在一个新的服务器上,所以我在本地回购上创建了一个新的远程存储库,并将其推送到该服务器上。
但现在当我做git拉,它声称我是最新的。这是错误的——它告诉我的是旧的远程分支,而不是新分支,我知道新分支实际上有新的提交要获取。
如何更改本地分支以跟踪不同的远程?
我可以在git配置文件中看到这一点,但我不想把事情搞砸。
[branch "master"]
remote = oldserver
merge = refs/heads/master
当前回答
git fetch origin
git checkout --track -b local_branch_name origin/branch_name
or
git fetch
git checkout -b local_branch_name origin/branch_name
其他回答
git fetch origin
git checkout --track -b local_branch_name origin/branch_name
or
git fetch
git checkout -b local_branch_name origin/branch_name
你可以删除你当前的分支,然后这样做:
git branch --track local_branch remote_branch
或者在配置中将远程服务器更改为当前服务器
根据我从最新的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 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