What is the git checkout master vs git checkout origin/master [duplicate]

What is the difference between the following commands?

git checkout master vs git checkout origin/master
0

1 Answer

git checkout master checks out a local branch. Typical.

git checkout origin/master looks similar and could suggest that you want to checkout a branch, but there the ref is a remote-tracking branch. These refs are not local branches, they're images of some remote's (origin) branches, which are only updated through git fetch. Checking them out like you would for a local branch is not allowed by git architecture, so it falls down to the next best thing : checking out the commit this ref is currently pointing at.

The result (of checking out a commit directly rather than a branch) is what's called a detached HEAD state. Harmless despite its name, it just means that your HEAD is currently pointing at a commit directly, not a branch. Which is "solved" by checking out a branch.

2

You Might Also Like