Skip to content

Instantly share code, notes, and snippets.

@alekpopovic
Forked from xtream1101/Backup&RestoreRepo.md
Created April 1, 2025 18:11
Show Gist options
  • Save alekpopovic/531df49fbd3a4ca55c44ed947f415028 to your computer and use it in GitHub Desktop.
Save alekpopovic/531df49fbd3a4ca55c44ed947f415028 to your computer and use it in GitHub Desktop.
Backup and restore a git repo using git bundle

Backup/archive a repo

  1. Clone the repo
git clone --mirror https://github.com/vuejs/vue
  1. cd into the cloned repo
  2. Create a bundle file in the parent directory
git bundle create ../vuejs_vue.bundle --all
  1. That bundle file is now a full archive of the repo, including all of its branches and tags

Restore a repo from a bundle file

Here we will restore the repo from the bundle and create a new remote origin that will contain all brnaches and tags

  1. Clone the repo from the bundle
git clone vuejs_vue.bundle
  1. Get all the branches locally to be pushed up to your origin later (from: https://gist.github.com/grimzy/a1d3aae40412634df29cf86bb74a6f72)
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
  1. Create a new repo on your git server and update the origin of the local repo
git remote set-url origin [email protected]/xtream1101/test-backup.git
  1. Push all branches and tags to the new remote origin
git push --all
git push --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment