0

I have a repo which has a lot of branchs(200+).

And I cloned it using git clone xxxx.git

But when I show branches, it only shows few:

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

When I trying to checkout a remote branch origin/release-1.6.2, it says no such branch(it exactly exists in my gitlab's web page).

enter image description here

$ git checkout origin/release-1.6.2
error: pathspec 'origin/release-1.6.2' did not match any file(s) known to git.

when I trying to fetch this branch, it seems this branch really exists.

$ git fetch origin origin/release-1.6.2
From gitlab.alipay-inc.com:blink/blink-tables
 * remote-tracking branch  origin/release-1.6.2 -> FETCH_HEAD

so how can I checkout this remote branch correctly?

it's different from this question, because I can not even see the branch in git branch -a

Lixin Wei
  • 441
  • 5
  • 17
  • Possible duplicate of [Git: cannot checkout branch - error: pathspec '...' did not match any file(s) known to git](https://stackoverflow.com/questions/5989592/git-cannot-checkout-branch-error-pathspec-did-not-match-any-files-kn) – CodeCaster Jun 11 '18 at 08:48
  • Are you sure it's not a tag? – Lasse V. Karlsen Jun 11 '18 at 08:56
  • @LasseVågsætherKarlsen No, it is in the `branch` tag in web page. – Lixin Wei Jun 11 '18 at 09:01
  • Are you sure that you have the correct repo? Perhaps you should clone it again and test it. – René Höhle Jun 11 '18 at 09:05
  • what is the o/p of this command. Can you confirm if anyone had not modifies the behaviour of git branch $git branch -r – Bijendra Jun 11 '18 at 09:07
  • @Stony Yes, I'm using the url provided in gitlab's web page. I've tried more than 3 times. – Lixin Wei Jun 11 '18 at 09:10
  • @Bijendra what do you mean by "o/p"? `git branch -r ` shows exactly the same result with `git branch -a` excepting the branch `master`. – Lixin Wei Jun 11 '18 at 09:14
  • Can you checkout the exact commit (`186eafef`)? – bimlas Jun 11 '18 at 09:15
  • @bimlas Yes, I can checkout this commit. But why checking out branch doesn't work? – Lixin Wei Jun 11 '18 at 09:26
  • When checked out, run `git describe` - it shows the tags of the commit. If it's contains `release-1.6.2`, then it's a tag. If not, then it's merged and the branch is deleted in my opinion. – bimlas Jun 11 '18 at 09:31
  • ... I see some confusion: did you named the branch exactly as `origin/release-1.6.2` instead of `release-1.6.2`? – bimlas Jun 11 '18 at 09:33
  • @bimlas Exactly `origin/release-1.6.2`. I asked my partner, He says it's a mirror branch to another repo. – Lixin Wei Jun 11 '18 at 09:38
  • If the answer is yes, then you can checkout as `git checkout origin/origin/release-1.6.2`, but you should rename it on the local repo (`git branch -m release-1.6.2`), push it (`git push`) and delete the previous branch from remote (`git push origin :origin/origin/relase-1.6.2`). – bimlas Jun 11 '18 at 09:40

1 Answers1

2

You named the branch incorrectly: GitLab shows origin/release-1.6.2 in the list of branches, thus the branch name is exactly origin/release-1.6.2. If you want to checkout, use

$ git checkout origin/origin/relase-1.6.2

To avoid confusion, remove the leading origin/ in the branch name by

  • renaming the local branch

    $ git branch -m origin/release-1.6.2 release-1.6.2

  • deleting the remote branch

    $ git push origin :origin/origin/release-1.6.2

  • pushing the renamed branch

    $ git push origin release-1.6.2

You can earn the branch (release-1.6.2) on the remote (origin) as origin/release-1.6.2).

Community
  • 1
  • 1
bimlas
  • 2,359
  • 1
  • 21
  • 29
  • Ah, good catch. Note that you have a typo in your branches as you've written it "relase", with a missing e, but good catch on the `origin/` actually being part of the *remote* branch name. – Lasse V. Karlsen Jun 11 '18 at 13:37