gitgit-bundle

How to clone repository along with changes from bundle?


I have a git repository, and a git bundle file. I can checkout the repository, and apply the bundle on one machine. I would like to use this particular machine as a mirror for this repository, along with the changes from the bundle. However when I try to clone it, the bundle changes don't seem to come across.

This is what I do on machine-A:

git clone git@example.com/repo.git
wget https://example.com/extra-upstream.bundle
cd repo
git fetch ../extra-upstream.bundle '+refs/heads/*:refs/remotes/extra/*'

This seems to work fine so far - I have the changes I expected.

On machine-B I do the following:

git clone git@machine-A:/repo

However only the upstream code is cloned, without the branches/remotes from the bundle. What am I missing?


Solution

  • Since you want mention that you want to create a "mirror", clone with --mirror, which will get you the remote-tracking branches of the remote repository as well:

    --mirror

    Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.


    Alternatively, specify additional refspecs for your remote:

    git config --add remote.origin.fetch '+refs/remotes/extra/*:refs/remotes/extra/*'
    

    Or fetch them explicitly without any configuration:

    git fetch origin '+refs/remotes/extra/*:refs/remotes/extra/*'
    

    Both forms will mirror the "extra" remote namespace of the remote repository locally when you fetch.