gitgit-bundle

How to use git-bundle for keeping development in sync?


I need to keep my development trees in sync on different computers, with no network connection between them.

We have a central git repository, and I normally work on my own clone on my office computer. Sometimes I need to do some development on another computer, which is never connected to the office network. None of the computers are ever connected to Internet. Development may be performed on both computers between synchronizations.

I have read the help pages for git-bundle, which seems like the best tool, but I am not really sure how a good workflow could be set up.

Can you give me some advice or pointers?


Solution

  • Bundles!

    The workflow with git bundle is going to be essentially the same as any other workflow. This may not seem like terribly helpful advice, but here it is: use whatever workflow you would normally use, and replace "push/pull" with "carry a bundle here to there on a flash drive, then pull".

    The man page actually has a pretty good walkthrough for getting going with this, although it's more of a one-way example. For the sake of completeness, here's a slightly modified version of it, showing how to move information both ways:

    # on hostA, the initial home of the repo
    hostA$ git bundle create hostA.bundle --branches --tags
    
    # transfer the bundle to hostB, and continue:
    hostB$ git clone /path/to/hostA.bundle my-repo
    # you now have a clone, complete with remote branches and tags
    # just to make it a little more obvious, rename the remote:
    hostB$ git remote rename origin hostA
    
    # make some commits on hostB; time to transfer back to hostA
    # use the known master branch of hostA as a basis
    hostB$ git bundle create hostB.bundle ^hostA/master --branches --tags
    
    # copy the bundle back over to hostA and continue:
    hostA$ git remote add hostB /path/to/hostB.bundle
    # fetch all the refs from the remote (creating remote branches like hostB/master)
    hostA$ git fetch hostB
    # pull from hostB's master, for example
    hostA$ git pull
    
    # make some commits on hostA; time to transfer to hostB
    # again, use the known master branch as a basis
    hostA$ git bundle create hostA.bundle ^hostB/master --branches --tags
    # copy the bundle to hostB, **replacing** the original bundle
    # update all the refs
    hostB$ git fetch hostA
    
    # and so on and so on
    

    The key thing to notice is that you can add a bundle as a remote, and interact with it just as you would with any other remote. To update that remote, just drop in a new bundle, replacing the previous one.

    I've also taken a slightly different approach to picking a basis. The man page uses tags, always kept up to date with the last refs which were transferred to the other host. I've simply used the remote branches, which will refer to the last refs transferred from the other host. It's a little bit inefficient; you'll end up bundling more than you need to, since it's one step behind. But flash drives are big, bundles are small, and using the refs you already have instead of having to take an extra step and be careful about tags saves a lot of effort.

    The one thing that makes bundles a bit of trouble is that you can't push to them, and you can't "rebase" them. If you want the bundle based on a new basis, you have to recreate it. If you want new commits in it, you have to recreate it. This hassle gives rise to my next suggestion...

    Repo on a thumb drive

    Honestly, unless your repo is really big, this might be just as easy. Put a bare clone on a thumb drive, and you can push to and pull from it from both computers. Treat it like your network connection. Need to transfer to the central repo? Plug it in!