使用来自跟踪的远程分支的更改更新本地分支 [英] Update a local branch with the changes from a tracked remote branch

查看:196
本文介绍了使用来自跟踪的远程分支的更改更新本地分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 my_local_branch 的本地分支,该分支跟踪一个远程分支 origin / my_remote_branch

I have a local branch named 'my_local_branch', which tracks a remote branch origin/my_remote_branch.

现在,远程分支已更新,我在' my_local_branch '上,并希望进行这些更改。我应该这样做吗?

Now, the remote branch has been updated, and I am on the 'my_local_branch' and want to pull in those changes. Should I just do:

git pull origin my_remote_branch:my_local_branch

这是正确的方法吗?

推荐答案

您已设置上游该分支的

(请参阅:


git branch -f --track my_local_branch origin/my_remote_branch
# OR (if my_local_branch is currently checked out):
$ git branch --set-upstream-to my_local_branch origin/my_remote_branch

git branch -f --track 如果布朗克不起作用h已检出:使用第二个命令 git branch --set-upstream-to ,否则将得到致命错误::无法强制更新))

(git branch -f --track won't work if the branch is checked out: use the second command git branch --set-upstream-to instead, or you would get "fatal: Cannot force update the current branch.")

这意味着您的分支为已配置,其中:

That means your branch is already configured with:

branch.my_local_branch.remote origin
branch.my_local_branch.merge my_remote_branch

Git已经拥有所有必要的信息。

在这种情况下:

Git already has all the necessary information.
In that case:

# if you weren't already on my_local_branch branch:
git checkout my_local_branch 
# then:
git pull

就足够了。

如果没有的话在推' my_local_branch '时建立上游分支关系,然后简单的 git push -u origin my_local_branch:my_remote_branch 足以推动并设置上游分支。

之后,对于随后的拉取/推动,再次使用 git pull git push 就足够了

If you hadn't establish that upstream branch relationship when it came to push your 'my_local_branch', then a simple git push -u origin my_local_branch:my_remote_branch would have been enough to push and set the upstream branch.
After that, for the subsequent pulls/pushes, git pull or git push would, again, have been enough.

这篇关于使用来自跟踪的远程分支的更改更新本地分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆