Skip to content

Instantly share code, notes, and snippets.

@xtream1101
Created June 29, 2019 12:38
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xtream1101/fd79f3099f572967605fab24d976b179 to your computer and use it in GitHub Desktop.
Save xtream1101/fd79f3099f572967605fab24d976b179 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 git@github.com/xtream1101/test-backup.git
  1. Push all branches and tags to the new remote origin
git push --all
git push --tags
@keyserjaya
Copy link

keyserjaya commented Dec 7, 2022

Got this error in windows power shell, please help :'

PS D:\WebProjects\Restore\spectator-v2.git\repo> git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
At line:1 char:54
+ git branch -r | grep -v '\->' | while read remote; do git branch --tr ...
+                                                      ~
Missing statement body in do loop.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingLoopStatement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment