Git- Tracking remote branches

萝らか妹 提交于 2019-12-07 02:35:21

问题


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:

  • whenever I git pull, changes to origin/dev are merged into dev
  • whenever I git push, changes to dev are merged into origin/dev

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?


回答1:


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.



来源:https://stackoverflow.com/questions/11666286/git-tracking-remote-branches

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!