Backup git repository
Git can “bundle” its data into a single file using the bundle
command.
This command packages everything that would typically be pushed over the network with a git push
into a binary
file. The file can then be emailed to someone, transferred to a flash drive, and later “unbundled” into another repository.
Following bash function will clone repository and create one single bundle file with nice name:
Usage:
PS: Note that git bundle only copies commits that lead to some reference (branch or tag) in the repository. So tangling commits are not stored to the bundle.
You can also create nice alias in .gitconfig
file:
Backup alias can be also found in my dotfiles repository.
Restore
You can directly clone repository from bundle file:
Or you can create empty repository and pull from bundle file:
Backup whole GitHub account
You can use GitHub API to get list of all user repos. Then you have to apply all your bash magic power to getting right names from that.
Or there are a number of tools specifically designed for the purpose of manipulating JSON from the command line. One of the best seems to me jq