How do I update my bare repo?

后端 未结 7 769
滥情空心
滥情空心 2020-11-29 16:14

I created a bare repo to publish my repository, but I can\'t figure out how to update the bare repo with the current state of the main repository.

相关标签:
7条回答
  • 2020-11-29 16:43

    After much messing around I've found that this works for me.

    Once:

    git clone --mirror ssh://git@source.address:2000/repo
    git remote add remote_site ssh://git@remote_site.address/repo
    git config remote.origin.fetch 'refs/heads/*:refs/heads/*'
    

    Everytime I want to sync:

    cd /home/myhome/repo.git
    git --bare fetch ssh://git@source.address:2000/repo
    git  fetch ssh://git@source.address:2000/repo
    git push --mirror remote_site
    
    0 讨论(0)
  • 2020-11-29 16:44

    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!

    0 讨论(0)
  • 2020-11-29 16:47

    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

    0 讨论(0)
  • 2020-11-29 16:47

    Assuming:

    $ git clone --bare https://github.com/.../foo.git
    

    Fetch with:

    $ git --git-dir=foo.git fetch origin +refs/heads/*:refs/heads/* --prune
    

    Note: --git-dir=foo.git is not required if you cd to the directory first.

    0 讨论(0)
  • 2020-11-29 16:50

    Add the bare repository as a remote repository, then use git push.

    0 讨论(0)
  • 2020-11-29 16:56

    For me this combination worked:

    git remote add remote_site https://github.com/project/repo.git
    git fetch -u remote_site +refs/heads/*:refs/heads/*
    git fetch -u remote_site +refs/tags/*:refs/tags/*
    git push --mirror
    

    -u parameter for fetch was necessary, otherwise I get the error message: "Refusing to fetch into current branch refs/heads/master of non-bare repository" (see also https://stackoverflow.com/a/19205680/4807875)

    0 讨论(0)
提交回复
热议问题