Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Last active July 4, 2023 07:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erkobridee/c09222adb2180c3628b53a8f0994733c to your computer and use it in GitHub Desktop.
Save erkobridee/c09222adb2180c3628b53a8f0994733c to your computer and use it in GitHub Desktop.
useful way to backup a whole repository from on remote to another remote server on an Unix base system
# define a full backup of a git repository from one remote server to another one
origin="https://remote-source/repository.git";
target="https://remote-target/repository.git";
workDir="temp-directory";
mkdir $workDir
cd $workDir
git clone --mirror $origin .
git remote set-url --push origin $target
git show-ref | cut -d' ' -f2 | grep 'pull' | xargs -r -L1 git update-ref -d
git push --mirror
cd ..
rm -rf $workDir
mkdir temp \
&& cd temp \
&& git clone --mirror https://remote-source/repository.git . \
&& git remote set-url --push origin https://remote-target/repository.git \
&& git show-ref | cut -d' ' -f2 | grep 'pull' | xargs -r -L1 git update-ref -d \
&& git push --mirror \
&& cd .. \
&& rm -rf temp
@erkobridee
Copy link
Author

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