Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
3 views
in DevOps and Agile by (29.3k points)

Which one of these lines is correct?

git checkout 'another_branch'

Or

git checkout origin 'another_branch'

Or

git checkout origin/'another_branch'

And what is the difference between these lines?

1 Answer

+3 votes
by (19.4k 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

Browse Categories

...