I am creating incremental bundles of my git repository using:
#!/bin/bash
if [ ! -f ./source0.bundle ]; then
git bundle create source0.bundle --all
elif [ $(git rev-parse HEAD) != $(git bundle list-heads source0.bundle | head -1 | cut -d' ' -f1) ]; then
declare -i LARGEST_NUMBER=$(ls | grep "source.*\.bundle" | tail -1 | grep -o '[0-9]*')
LARGEST_NUMBER_PLUS_ONE=$((LARGEST_NUMBER 1))
git bundle create source${LARGEST_NUMBER_PLUS_ONE}.bundle $(git bundle list-heads source${LARGEST_NUMBER}.bundle | head -1 | cut -d' ' -f1)..HEAD
fi
It creates source0.bundle
, source1.bundle
, source2.bundle
....
To restore the bundles, I have to run:
$ git clone source0.bundle extract
$ cd extract
$ for ((i = 1 ; i < 3 ; i )); do git pull ../source${i}.bundle; done
Is this a good approach or am i complicating things?
CodePudding user response:
man git-bundle
DESCRIPTION Create, unpack, and manipulate "bundle" files. Bundles are used for the "offline" transfer of Git objects without an active "server" sitting on the other side of the network connection.
This is the first time I hear about git bundles. If you need to maintain a copy of your repository somewhere, you can create a remote to a local folder like:
git remote add secondary /backup/foo/bar.git
Then you can push to this remote.
git push secondary master
There are some quirks, such as not being able to push to a checked-out remote, but you can make it a "bare" remote as in a "server" remote.
git init --bare /backup/foo/bar.git
Pushing to a bare repository is same as pushing to github or bitbucket.
In my opinion, you don't need bundles unless you know you do. If in doubt, you don't need them.