gitgithubgit-bundle

git bundle: two-way all branches sync between local and remote repo


Machine A has Internet connection while machine B does not. Both have local repository and machine A can interact with Github. Development happens on both the machines. git-bundle is being used to keep the repositories in sync.

Usual flow of syncing:

  1. Create a bundle of all the branches in B and transfer the bundle to A.

  2. Clone github repository on A. Pull all branches from bundle into the repository cloned from github. Push the updated repository (all the branches) to github.

  3. Create a bundle of all the branches from github repository. Transfer the bundle to B. Pull all branches from bundle into the repository on B.

There is a way to create a bundle of all the branches of repository. But is there a way to pull all the branches of a bundle into local repository at once?

The two-way sync-up seem to be straight forward in case of single branch repositories.


Solution

  • Since a bundle is just like any other repository – the only difference being that a bundle happens to be stored as a single file – you can use git pull --all to fetch all branches from the bundle and merge them into their corresponding tracking branches:

    git pull --all /path/to/bundle
    

    Note, however, that the --all option only applies to git fetch. This means that only the current local branch (i.e. the one referenced by HEAD) is going to be updated. If you want to also update all local branches, you'll have to write a script for it yourself or use something like git-up.