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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With