Is `pull` needed after checking out a new branch?

非 Y 不嫁゛ 提交于 2021-02-07 13:28:15

问题


In case of a git-project with several branches, the question is when you checkout a new branch (first time), is a git pull needed ?

$master> git checkout branchA
$branchA> git pull

Note that the idea here is that both commands are executed right after each other (this question is not about when-or-why you should run git pull)

I've tested this, but so far the pull doesn't pull in new commits, but some people claim that the pull is needed. Can someone describe a scenario in which this is indeed needed or maybe break this myth?


回答1:


If the branch is already on origin and you do not have a local copy and you check it out, then it will contain all commits anyway so you do not need the pull after. If you already have a local copy of the branch it will checkout that one, and in that case you use git fetch origin to see if there have been any changes and the git pull to get those changes. if your branch is not set up to track the remote branch then you will need to add the branch name at the end of the pull, eg git pull origin branchA



来源:https://stackoverflow.com/questions/30912024/is-pull-needed-after-checking-out-a-new-branch

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