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
  • Select an option

  • Save alekpopovic/531df49fbd3a4ca55c44ed947f415028 to your computer and use it in GitHub Desktop.

Select an option

Save alekpopovic/531df49fbd3a4ca55c44ed947f415028 to your computer and use it in GitHub Desktop.

Revisions

  1. @xtream1101 xtream1101 revised this gist Jun 29, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Backup&RestoreRepo.md
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ Here we will restore the repo from the bundle and create a new remote origin tha
    ```
    3. 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
    git remote set-url origin [email protected]/xtream1101/test-backup.git
    ```
    4. Push all branches and tags to the new remote origin
    ```
  2. @xtream1101 xtream1101 created this gist Jun 29, 2019.
    33 changes: 33 additions & 0 deletions Backup&RestoreRepo.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # Backup/archive a repo
    1. Clone the repo
    ```
    git clone --mirror https://github.com/vuejs/vue
    ```
    2. `cd` into the cloned repo
    3. Create a bundle file in the parent directory
    ```
    git bundle create ../vuejs_vue.bundle --all
    ```
    4. 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
    ```
    2. 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
    ```
    3. 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
    ```
    4. Push all branches and tags to the new remote origin
    ```
    git push --all
    git push --tags
    ```