2

My co-developer made a lot of changes on his remote gitlab repository: merged, deleted, created new branches etc.

Now I need to work on a new feature branch that he's just created. I open my Gitbash, do:

git pull git@gitlab.example.com:root/project-name.git
git checkout new-feature

I get error: pathspec 'new-feature' didn't match any file(s) known to git.

Then I tried:

git show-ref

This only shows two branches, while it should show at least 8. I also tried fetch which made no difference whatsoever.

Are the files really missing or is it simply not tracking the new branches? How do I get the new branch to my local workspace? Would git clone solve it or only make it worse? Thanks.

UPDATE: Thank you for your help, unfortunately, neither of the suggestions worked and I had to delete everything, set it up from scratch and do a fresh git clone. We looked through the error logs but didn't find any clues. Just one of those things, I guess.

Hanzo Hasashi
  • 111
  • 2
  • 9
  • Have you asked your co-worker if he pushed his new branch to the `origin`? If so, have you tried `git pull origin new-feature`? – NuclearPeon Aug 26 '15 at 20:44
  • What does `git branch -a` tell you? – jub0bs Aug 26 '15 at 20:44
  • `git pull git@gitlab.example.com:root/project-name.git` - does that even work? – M.M Aug 26 '15 at 21:26
  • Matt McNabb, yeah, why wouldn't it? That's how I got the files last time. Does it look wrong? – Hanzo Hasashi Aug 26 '15 at 22:15
  • Jubobs, same as `git show-ref` - i.e. I've got 2 branches, not 8. – Hanzo Hasashi Aug 26 '15 at 22:16
  • NuclearPeon, can't ask him, he's gone unresponsive. If I try your suggestion, I get: fatal: `origin does not appear to be a git repository` – Hanzo Hasashi Aug 26 '15 at 22:19
  • *[...] while it should show at least 8.* What makes you think that? If your coworker deleted branches and you then pulled from the remote, those branches will have ceased to exist in your local repo also. It looks like the remote doesn't have any branch called `new-feature`, if it ever had one. – jub0bs Sep 01 '15 at 17:55

3 Answers3

5

I know this is an old thread, but I just stumbled over it because I had the same problem. After checking 'man git' I found out that 'git fetch' does the trick. So, for anyone who might come across this topic in the future:

  1. Go to a terminal.
  2. Navigate to the project directory.
  3. Enter git fetch.

As the description of git fetch states:

Fetch branches and/or tags (collectively, "refs") from one or more other repositories, along with the objects necessary to complete their histories. Remote-tracking branches are updated (see the description of below for ways to control this behavior).

Shoptimizer
  • 111
  • 2
  • 8
0

You can try getting the branch on remote

git checkout origin/branch-name

Also, we use network graph in gitlab UI heavily to check any inconsistencies with the branch.

Pankaj Gadge
  • 2,748
  • 3
  • 18
  • 25
  • Thanks, when I do this, I get the same pathspec error as before. Just logged in to check his gitlab dashboard and the Network section looks logical. I can see all 8 branches. Still I can only access two on my machine. – Hanzo Hasashi Aug 26 '15 at 22:37
0

You need to give a name to the repository first:

git remote add somerepo git@gitlab.example.com:root/project-name.git

Then when you do a pull git will store the remote tracking branches in somerepo/new-feature, and when you do git checkout new-feature it will create a new local branch based on that.

When you do git pull <url> only the HEAD is fetched, and it's stored in FETCH_HEAD, which is probably not what you want.

FelipeC
  • 9,123
  • 4
  • 44
  • 38