How do I update my bare repo?
If you want to duplicate all the objects from the main repo, do this inside the main repo:
git push --all <url-of-bare-repo>
Alternatively, do a fetch inside the bare repo:
git fetch <url-of-main-repo>
You cannot do a pull, because a pull wants to merge with HEAD
, which a bare repo does not have.
You can add these as remotes to save yourself some typing in the future:
git remote add <whatever-name> <url-of-other-repo>
Then you can simply do
git push --all <whatever-name>
or
git fetch <whatever-name>
depending on what repo you're in. If <whatever-name>
is origin
, you can even leave it out altogether.
Disclaimer: I'm not a git guru. If I said something wrong, I'd like to be enlightened!
Update: Read the comments!
I created a repository using the following command
git clone --bare <remote_repo>
Then I tried to update the bare clone using the answer by Thomas, but it didn't work for me. To get the bare repository to update (which is what I think Let_Me_Be was asking), I had to create a mirror repository:
git clone --mirror <remote_repo>
Then I could run the following command in the mirrored repository to grab the main repository's updates:
git fetch --all
I came across this solution by reading Mirror a Git Repository By Pulling
The only solution besides recreating with git clone --mirror
is from Gregor:
git config remote.origin.fetch 'refs/heads/*:refs/heads/*'
then you can git fetch
and you'll see the updates. The weird thing is that before this, even though there is a remote
configured, it has no branches listed in git branch -a
.