Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I synchronize git branches between bare repositories?

Tags:

git

I have a bare repository, whose origin 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?


Note: 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 config is the following:

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

My config in a newly cloned (also bare) repo:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
[remote "origin"]
        url = git://host/project.git
like image 578
peterh Avatar asked Sep 15 '16 16:09

peterh


People also ask

What is git clone mirror?

A clone copies the refs from the remote and stuffs them into a subdirectory named 'these are the refs that the remote has'. A mirror copies the refs from the remote and puts them into its own top level - it replaces its own refs with those of the remote.


1 Answers

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.

like image 74
yaba Avatar answered Sep 30 '22 18:09

yaba