2

I have a git repo checked out from github, but it refuses to acknowledge any remote branches.

Here's what I've tried (names changed to protect the guilty):

$ git pull
Already up-to-date.
$ git fetch
$ git remote update
Fetching origin
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
$ git remote show
origin
$ git remote show origin
* remote origin
  Fetch URL: git@github.com:Someplace/someproject.git
  Push  URL: git@github.com:Someplace/someproject.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)
$ git remote -v
origin  git@github.com:Someplace/someproject.git (fetch)
origin  git@github.com:Someplace/someproject.git (push)

On another machine, it just works:

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/somebranch
  ...
Karl
  • 14,434
  • 9
  • 44
  • 61
  • 1
    Can you show the contents of you .git/config file? In particular, the `[remote "origin"]` section? I wonder if your fetch line is different than usual for some reason. It should generally be something like `fetch = +refs/heads/*:refs/remotes/origin/*`. – John Szakmeister Mar 10 '17 at 20:12
  • They may have been removed by accident. What does a fresh clone say about remotes? What does github itself think? – Thorbjørn Ravn Andersen Mar 10 '17 at 20:17
  • Fresh clone still doesn't work. The git config has this: `fetch = +refs/heads/master:refs/remotes/origin/master` – Karl Mar 10 '17 at 20:22
  • @Karl your fetch-string tells only to fetch `master`, please change it to line with `*` as in jszakmeister's example. – kan Mar 10 '17 at 20:27
  • So am I going to have to manually edit the config file every time I fetch a new repo? – Karl Mar 10 '17 at 20:27
  • What are you using for your `git clone` command? Are you passing `--single-branch`? Can you include the output of `git config -l` in your question too? Perhaps you have a config setting that's affecting you (though I can't think of what that would be off-hand) – John Szakmeister Mar 12 '17 at 16:59
  • Oh, and someone else said it, but it's worth repeating. You're fetch line says to only update master, which is why you are seeing the other branches. Replacing `master` with `*` would fix your issue, but if new clones are doing this to you, we should figure out why. – John Szakmeister Mar 12 '17 at 17:01
  • Yes that was my point. It was a brand new clone that was doing this. And I wasn't using single-branch. – Karl Mar 13 '17 at 17:47

1 Answers1

1

First, you can confirm the existence of remote branches with git ls-remote

cd /patH/to/my/repo
git ls-remote

Or, from any directory:

git ls-remote git@github.com:Someplace/someproject.git

Second, make sure your local repo is set to fetch all branches with the right refspec:

git config remote.origin.fetch refs/heads/*:refs/remotes/origin/*

(as suggested by kan)

am I going to have to manually edit the config file every time I fetch a new repo?

No because refs/heads/*:refs/remotes/origin/* is the default refspec used by any git clone.
Unless, as torek mentions, you use git clone --single-branch, which is possible since Git 1.7.10.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    It's worth noting here that a `--single-branch` clone changes the default refspec. It seems likely that Karl is using `git clone --single-branch` instead of plain `git clone`. – torek Mar 11 '17 at 01:27
  • @torek it is worth noting indeed. I have edited the answer accordingly. – VonC Mar 11 '17 at 05:45
  • I'll mention that this WAS a plain `git clone` (no command line switches) that set the refspec wrong, and still does it every time. – Karl Mar 11 '17 at 15:07
  • Also, when the refspec is wrong, even `git ls-remote` won't show anything. – Karl Mar 11 '17 at 15:08