Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check out a branch that exists in a remote

Tags:

git

github

I'm using git version 1.8.3.1 (centos 7). I have a repository on github with a bunch of branches. I clone that repository and attempt to check out one of those branches, but it won't let me:

$ git clone my_repo
$ cd my_repo
$ git checkout my_desired_branch
error: pathspec 'my_desired_branch' did not match any file(s) known to git.

I know that this branch exists in the remote branch; I pushed it from another computer, and I can check it out on github no problem. Reading up on similar issues on stack overflow, the answers seem to variously consist of:

$ git fetch [--all]
$ git pull [--all]

However, none of these things solve my problem. Furthermore, no matter what I do, nothing except the master branch shows up when I list my branches:

$ git branch
* master
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
$ git branch -r
  origin/HEAD -> origin/master
  origin/master

I also can't fetch my branch from the repo by hash:

$ git fetch origin 6175e3ae4c88669af8aa5cd12b

This command gives no output, even with --verbose... but inspecting the exit code shows that it's 1. And of course:

$ git checkout 6175e3ae4c88669af8aa5cd12b
fatal: reference is not a tree: 6175e3ae4c88669af8aa5cd12b

This is really frustrating. At this point I've tried seemingly every possible combination of fetch, pull, and branch, and no matter what I do, I can't get my local clone of this repo to even show that these branches exist, let alone let me check them out.

What is happening here? It seems like the simplest thing in the world: given that my repo has some branch that I want, clone the repo and check out that branch.

like image 612
limp_chimp Avatar asked Mar 14 '23 09:03

limp_chimp


1 Answers

To make sure you fetch all the branches from the remote, try:

git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git fetch --all

See: How to fetch all remote branches?

like image 178
kenorb Avatar answered Mar 16 '23 05:03

kenorb