Manish Patel
Manish Patel

Reputation: 4491

What causes git checkout to not work (and not switch to branch)

This one is super odd. I create a fresh clone of a repository. For one of the branches (web) I cannot do a checkout - I issue the command and the directory stays in the current branch without showing any error. I can checkout origin/web though, but I'm just interested to know why I can't check out the attached branch.

All other branches work ok, as illustrated below. Note the first time, it stays on master without error.

enter image description here

Upvotes: 0

Views: 651

Answers (2)

Eddie Curtis
Eddie Curtis

Reputation: 1237

This is surprising because there doesn't seem to be a current "web" branch.

Maybe try the following commands and see where you get:

git branch -D web # Delete any existing web branch
git fetch origin web # Fetch the web branch from the origin
git checkout -b web origin/web # Create a new local "web" branch that tracks the remote

Upvotes: 1

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522561

When you typed git branch -a | grep web, you told Git to list all the branches containing web in the name, both local ones and remote tracking branches. The output was this:

remotes/origin/web
remotes/origin/web-admin

In other words, there is no local web branch. As to why you didn't get a formal error message about the web branch not existing, I am not certain.

If you want to create a local branch which tracks the remote web branch then do so via:

git checkout origin/web
git checkout -b web

Upvotes: 1

Related Questions