+3 votes
1 view
in DevOps and Agile by (30k points)

Which one of these lines is correct?

git checkout 'another_branch'


git checkout origin 'another_branch'


git checkout origin/'another_branch'

And what is the difference between these lines?

1 Answer

+3 votes
by (20k points)
edited by

If branch already exists locally and you are not on this branch, then 

git checkout branch 

If branch does not exist but origin/branch does, then git checkout branch is equivalent to 

git checkout -b branch origin/branch

That's to create branch from origin/branch and set origin/branch as the upstream of branch.

git checkout origin/branch 

succeeds if origin/branch exists. It leads to be in detached HEAD state, not on any branch. If you make new commits, the new commits are not reachable from any existing branches and none of the branches will be updated.

For better understanding about these commands go through the following crash course on git that will help you to understand git well

Welcome to Intellipaat Community. Get your technical queries answered by top developers !