中央存储库必须设置在一个新的服务器上,所以我在本地回购上创建了一个新的远程存储库,并将其推送到该服务器上。

但现在当我做git拉,它声称我是最新的。这是错误的——它告诉我的是旧的远程分支,而不是新分支,我知道新分支实际上有新的提交要获取。

如何更改本地分支以跟踪不同的远程?

我可以在git配置文件中看到这一点,但我不想把事情搞砸。

[branch "master"]
    remote = oldserver
    merge = refs/heads/master

当前回答

我尝试了很多解决方案,但从Bitbucket到Azure Devops Migration,这个解决方案对我来说是有效的:

创建存储库 git clone源URL Git config——global——unset credentials .helper Git配置凭证。辅助存储 Git远程rm来源 git远程添加原始URL到NEW repo Git push origin——全部 以防错误使用 Git push -f origin——all 以防访问或身份错误 去分支——>select分支——>3 dots——>branch security——> allow force push Git push—标签

其他回答

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(2.5.5),命令如下:

git branch --set-upstream-to=origin/branch

这将更新当前本地分支的远程跟踪分支

你可以删除你当前的分支,然后这样做:

git branch --track local_branch remote_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 2.7.4版本中,

Git checkout branch_name #要更改跟踪分支的分支名称

Git分支——set-upstream-to=upstream/tracking_branch_name #upstream -远程名称