git 使用来自跟踪的远程分支的更改更新本地分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11278497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update a local branch with the changes from a tracked remote branch
提问by skyork
I have a local branch named 'my_local_branch
', which tracks a remote branch origin/my_remote_branch
.
我有一个名为“ my_local_branch
”的本地分支,它跟踪远程分支origin/my_remote_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:
现在,远程分支已更新,我在 ' my_local_branch
' 上并希望引入这些更改。我应该这样做吗:
git pull origin my_remote_branch:my_local_branch
Is this the correct way?
这是正确的方法吗?
采纳答案by VonC
You have set the upstream of that branch
您已经设置了该分支的上游
(see:
(看:
- "How do you make an existing git branch track a remote branch?" and
- "Git: Why do I need to do
--set-upstream-to
all the time?"
)
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
won't work if the branch is checked out: use the second command git branch --set-upstream
instead, or you would get "fatal: Cannot force update the current branch.
")
(git branch -f --track
如果分支被检出将不起作用:改用第二个命令git branch --set-upstream
,否则你会得到“ fatal: Cannot force update the current branch.
”)
That means your branch is already configuredwith:
这意味着您的分支已经配置了:
branch.my_local_branch.remote origin
branch.my_local_branch.merge my_remote_branch
Git already has all the necessary information.
In that case:
Git 已经拥有所有必要的信息。
在这种情况下:
# if you weren't already on my_local_branch branch:
git checkout my_local_branch
# then:
git pull
is enough.
足够。
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 andset the upstream branch.
After that, for the subsequent pulls/pushes, git pull
or git push
would, again, have been enough.
如果您在推送您的 ' my_local_branch
'时没有建立上游分支关系,那么一个简单的git push -u origin my_local_branch:my_remote_branch
就足以推送和设置上游分支。
在那之后,对于后续的拉/推,git pull
或者git push
再一次,已经足够了。
回答by Amber
You don't use the :
syntax - pull
always modifies the currently checked-out branch. Thus:
您不使用:
语法 -pull
始终修改当前签出的分支。因此:
git pull origin my_remote_branch
while you have my_local_branch
checked out will do what you want.
当你my_local_branch
签出时会做你想做的。
Since you already have the tracking branch set, you don't even need to specify - you could just do...
由于您已经设置了跟踪分支,因此您甚至不需要指定 - 您只需执行...
git pull
while you have my_local_branch
checked out, and it will update from the tracked branch.
当您my_local_branch
签出时,它将从跟踪的分支更新。