1

There is a bare remote (let's call it group_origin).
I made a bare mirror clone of it (my_origin).
I git clone my_origin to a repository with a working directory (my_rep).
In my_rep I code, push to my_origin and pull from my_origin.

When group_origin is updated by my colleagues, I git fetch my_origin from group_origin.
I see tags of the kind group_origin/branch_1 (when I execute git log inside of my_origin). Thus, my_origin is "aware of" newly created branch branch_1 on group_origin.
However, when I git pull my_origin from my_rep and git log within my_rep later, I don't see any notice of branch_1.

So, my question is:
how can I update my_rep from my_origin (which is in turn a bare mirror of group_origin) to fetch newly created branches of group_origin/branch_1?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
user1541776
  • 497
  • 4
  • 14

1 Answers1

1

You should create the tracking branches in my_origin for each and every branches from group_origin.

For that, I use that one-liner from the question "Track all remote git branches as local branches".

remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}'`; do git branch --set-upstream-to $brname  $remote/$brname ; done

Otherwise, by default, my_origin will only declare one branch (the default one from group_origin, referenced by its symbolic-ref HEAD).
And, in turn, my_rep will see only that one branch.


The other option is to add a remote to your local repo my_rep, for monitoring group_origin directly.
(You can add as many remote upstream repos that you want or need, just to have a look at their history)

cd my_rep
git remote add group_origin /url/to/group_origin
git fetch group_origin

That way, you will see those group_origin/branch_x and can decide to create one and push it to my_origin.

git checkout --track -b branch_x group_origin/branch_x
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Just curious, Is it an accepted/good practice to bare clone another bare repo? – Anshul Goyal Oct 10 '13 at 13:39
  • @ansh0l If you need to push to that intermediate repo, then that intermediate repo better be a bare one indeed, so it may be uncommon, but not a "bad" practice. – VonC Oct 10 '13 at 13:47
  • @VonC, thanks! The only thing is that on my git version I had to replace --set-upstream-to to --set-upstream in that one-liner. – user1541776 Oct 10 '13 at 14:18
  • @user1541776 then you must be using a old git version ;) – VonC Oct 10 '13 at 14:19
  • @user1541776 more specifically: http://stackoverflow.com/questions/10002239/difference-between-git-checkout-track-origin-branch-and-git-checkout-b-branch/10002469#10002469 You must be using a git previous to 1.8.0 (like the default one on Ubuntu). If so, use an up-to-date ppa like https://launchpad.net/~git-core/+archive/ppa. – VonC Oct 10 '13 at 14:27
  • @VonC, thank you for the comment. That's correct, I used the old one 1.7 – user1541776 Oct 10 '13 at 14:29