2

I have just cloned a git repo that already have a bunch of remote branches. I have poked around in the .git folder but I cannot find them, when I do a git show-ref I get:

cf8e5e98c27ee83a1ff2122f2c2a214e8e06383d refs/heads/master
cf8e5e98c27ee83a1ff2122f2c2a214e8e06383d refs/remotes/origin/HEAD
76541f13b20bb25056788f092f58547d4657bed8 refs/remotes/origin/example
cf8e5e98c27ee83a1ff2122f2c2a214e8e06383d refs/remotes/origin/master
cf8e5e98c27ee83a1ff2122f2c2a214e8e06383d refs/remotes/origin/smpl-remote
e34b3b7e54174c5b862ae16d29a3079c060c160e refs/remotes/origin/test

But the folder: .git\refs\remotes\origin only contains the HEAD file

If open the repo in eclipse I can see them:

enter image description here

What am I missing here?

I just tried to remove the internet connection (wifi and wired) but I can still list the remote branches, where in the .git folder is that information??

u123
  • 15,603
  • 58
  • 186
  • 303
  • 2
    Why are you doing this the hard way? What does `git branch -r` tell you? – Makoto Feb 17 '15 at 21:00
  • That is not really the point. Does it require online access to list remote branches? – u123 Feb 17 '15 at 21:02
  • If by "online" you mean "connected to a network that allows access to that particular Git server", then yes. They're branches that are on a remote server. – Makoto Feb 17 '15 at 21:03
  • 1
    You don't need access to them to list the remote branches, you DO need access to update them with `git fetch`. – Emil Davtyan Feb 17 '15 at 21:06
  • Ok I thought that when you cloned a repository you would get a local copy of each of the remote branches at the time you cloned the repo. The state of those branches would then be updated each time you do a git fetch – u123 Feb 17 '15 at 21:07
  • 2
    Check `.git\packed-refs` – Andrew C Feb 17 '15 at 21:11
  • @u123 You're correct. Makoto is incorrect. Only one local branch is checked out in a clone, but you get a copy of all the branches in that repo as *remote-tracking* branches; they're like local branches that you modify directly. See http://stackoverflow.com/questions/26125162/difference-between-origin-branch-name-and-branch-name/26125339#26125339 – jub0bs Feb 17 '15 at 21:31
  • 1
    @u123 Why exactly do you care where Git stores those remote-tracking branches, though? As a user that's none of your concern... – jub0bs Feb 17 '15 at 21:36

1 Answers1

4

Andrew C answered in a comment, but I'll add a bit more.

The "missing" branches are "packed". This saves space (and sometimes saves time although mostly that's a wash).

In fact, all branches get packed at various times (when git pack-refs runs, usually on behalf of git gc). That's one of several reasons you are supposed to use various front-end and back-end commands (git branch, git for-each-ref, git update-ref, git symbolic-ref) to work with branches, rather than just peeking into .git/refs/ directly.

It's sometimes convenient to add .git/packed-refs to your peeking, but remember that this part is an implementation detail and may change.

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775