peterh peterh - 1 year ago 114
Git Question

How can I synchronize git branches between bare repositories?

I have a bare repository, whose

is on a remote machine.

I would like to download its branches into the local bare repo. I.e. I want to see them with a
git branch -vva
command in the branch list, like so:

* master 0bc84f0 [origin/master] something...
remotes/origin/HEAD -> origin/master
remotes/origin/master 0bc84f0 something...

In the case of non-bare repos, a
git pull --all
synchronized also the branches (it made the remote branches visible in the local repository), but in the case of a bare repo, pull is impossible.

How can I sync the remote branches in this scenario?

git --fetch
doesn't work, the remote branches are still invisible after it:

$ git remote -v
origin git://host/project.git (fetch)
origin git://host/project.git (push)
$ git branch -vva
* master 4085a31 ...something
$ git fetch
From git://host/project.git
* branch HEAD -> FETCH_HEAD
$ git branch -vva
* master 4085a31 ...something

Additional info: my
is the following:

repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
[remote "origin"]
url = git://host/project.git

in a newly cloned (also bare) repo:

repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
url = git://host/project.git

Answer Source

Solution #1:

You need to convert your repo to a mirror repo:

git remote add --mirror=fetch origin <url>
git fetch

A mirror repo will keep to local references in sync with the origin references after a fetch. It has the disadvantage, that a mirror should be an exact copy of the remote repo, what may be not your goal.

Solution #2:

(Extension from @peterh using the comments):

In the git config (simply repo/config in the case of a bare repo), a

[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*

should exist. If it doesn't, it may be a non-trivial git feature, or a git bug. You can fix it by hand. After that, git fetch will work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download