Is a pull required after checking out a new branch?

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

?

$master> git checkout branchA
$branchA> git pull

      

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

)

I've tested this but pull

doesn't pull in new commits yet, but some people argue that it is required pull

. Can someone please describe a scenario where this is really needed, or perhaps interrupt this myth?

+3


source to share


1 answer


If the branch is already listed by origin and you don't have a local copy and you are checking it out, then it will contain all the commits so you don't have to pull after. If you already have a local copy of the branch, it checks it out, in which case you use git fetch origin

to see if there were any changes and 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, likegit pull origin branchA



+4


source







All Articles