Intellipaat Back

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

I'm not sure why I'm unable to checkout a branch that I had worked on earlier. See the commands below (note: co is an alias for checkout):

chandra@chandra-desktop:~/source/unstilted$ git branch -a

* develop

  feature/datts_right

  feature/user_controlled_menu

  feature/user_controlled_site_layouts

  master

  remotes/origin/HEAD -> origin/master

  remotes/origin/develop

  remotes/origin/feature/datts_right

  remotes/origin/master

chandra@chandra-desktop:~/source/unstilted$ git co feature/user_controlled_site_layouts 

error: pathspec 'feature/user_controlled_site_layouts' did not match any file(s) known to git.

I'm not sure what it means, and I can't seem to find anything I can understand on Google.

How do I checkout that branch, and what may I have done to break this?

2 Answers

+3 votes
by (50.2k points)
edited by

For this question, you need to try 

git fetch

So that your local repository gets all the new information from github. It just takes the information about new branches and actual code and it works fine after:

git checkout

This will help you to check out your branch.

You can also check out more Git commands on Git Tutorial.

Check out this video for git tutorial:

Git: cannot checkout branch - error: pathspec '…' did not match any file(s) known to git
Intellipaat-community
by (19.4k points)
If you have deleted a branch with git branch -D yourbranchname and pulled/cloned again your repo, you may need to create your local branch again.
0 votes
by (2.8k points)

You have local branches that aren’t yet linked to any branch on the remote repository.

To fix this, fetch the latest branches from the remote and check out the branch directly from there to access it again.

Here’s how:

  • Run git fetch origin to update the list of branches from the remote.

  • Then, try checking out the branch directly with git checkout -b feature/user_controlled_site_layouts 

This checkout command, checkout -b, tells Git to create a new branch on your local machine if it does not already exist and link it to the branch on the remote. You should now be able to work on it again.

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...