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

13.3k views Asked by At

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

There are 1 answers

0
bruceyyy On BEST ANSWER

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