Git-跟踪远程分支 [英] Git- Tracking remote branches
问题描述
我是Mercurial用户,我对远程分支的行为感到困惑。我有一个远程分支 origin / dev
,我想将它复制到本地分支 dev
中。我想要的是:每当我 git pull
时,
- ,变为<每当我
时,code> origin / dev
合并为dev
- > git push ,将
dev
的更改合并到origin / dev
中 - whenever I
git pull
, changes toorigin/dev
are merged intodev
- whenever I
git push
, changes todev
are merged intoorigin/dev
因此,我创建了一个跟踪分支,其中包含
pre $ git branch --track dev origin / dev
据我所知,应该完全按照我还需要什么。
不过,我正在开发一个功能分支,并发布了一个 git pull
。当我后来发出 git checkout dev
我收到了令人费解的信息
您的分支是在'origin / master_dev'后面提交2个提交,并且可以被快进。
所以看起来我的本地分支没有更新毕竟。有没有办法让分支更新到远程的每当我拉,我目前不在该分支?如果不是,我是否正确地指出分支开发中的 git merge
(没有任何参数)足以恢复情况?
git pull
。 当你在diff分支时, git pull
,它只是更新了 dev
的远程追踪分支。现在 git merge
足以更新本地分支 dev
。
I am a Mercurial user, and I am confused about the behaviour of remote branches. I have a remote branch origin/dev
, and I want to replicate it on a local branche dev
. What I would like is that:
So I created a tracking branch with
git branch --track dev origin/dev
which, to the best of my knowledge, should do exactly what I need.
Still, I was working on a feature branch and issued a git pull
. When I later issued git checkout dev
I received the puzzling message
Your branch is behind 'origin/master_dev' by 2 commits, and can be fast-forwarded.
So it seems that my local branch was not updated after all. Is there a way to have the branch updated to the remote one whenever I pull and I am not currently in that branch? If not, am I correct that git merge
(without any arguments) on branch dev is enough to restore the situation?
The command git pull
fetches updates from all remote branches (i.e, updates all the remote tracking branches). But merges only the current branch. This is a default behavior of git pull
when no argument passed.
As you were on a diff branch when you git pull
, it just updated the remote tracking branch for dev
. Now git merge
would be enough to update your local branch dev
.
这篇关于Git-跟踪远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!