Skip to content

Instantly share code, notes, and snippets.

@pixelbrackets
Last active August 28, 2020 12:51
Show Gist options
  • Save pixelbrackets/13c5cca26ea806c6386bf5e8f18bac7c to your computer and use it in GitHub Desktop.
Save pixelbrackets/13c5cca26ea806c6386bf5e8f18bac7c to your computer and use it in GitHub Desktop.
Duplicate / Mirror a git repository to another without forking
#!/usr/bin/env bash
# Usage:
# ./git-mirror-repository.sh "<source repository URL>" "<target repository URL>"
# Example:
# ./mirror-gitlos-project.sh "git@gitlab.com:example/kickstart.git" "git@gitlab.com:example/acme.git"
#
# The user must have access to both existing repositories
#
# Warning! --mirror will do a force push - Use only once per project!
echo "Mirror project $1"
cd $(mktemp -d)
pwd
git clone --mirror $1
cd $(ls -d */ | head -n 1)
git push --mirror $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment