These are shell functions to
- Create a git mirror repository from a original repository (
create_mirror
) - Update the mirror repository with the original repository changes (
update_mirror
)
You can add to your ~/.bash_profile
the following functions
# Initialize the repository to mirror
## Inputs: source_repository, target_repository
# Example: create_mirror [email protected]:source-profile/source-repository.git [email protected]:target-profile/target-repository.git
create_mirror() {
# Initializing the mirror.
git clone --mirror $1
cd `echo $1 | rev | cut -d '/' -f 1 | rev`
git remote set-url --push origin $2
# Updating the Mirror
git fetch -p origin
git show-ref | cut -d ' ' -f2 | grep 'pull' | xargs -L1 git update-ref -d # Delete PRs to let the push mirror work
git push --mirror
}
# Pushing changes to the mirror repository (Need to be inside the initialized repository)
## Inputs: none
# Example: update_mirror
update_mirror() {
git fetch -p origin
git show-ref | cut -d ' ' -f2 | grep 'pull' | xargs -L1 git update-ref -d # Delete PRs to let the push mirror work
git push --mirror
}
First, you need to create a blank repository, it will be used as a target repository to mirror the original repository.
Then, just execute the following command on the shell
create_mirror [email protected]:source-profile/source-repository.git [email protected]:target-profile/target-repository.git
And see the magic happen!
Later on, if you want to submit new commits from the original-repository
to the target-repository
, you just need to enter on the created /original-repository
folder and execute the following command
update_mirror
And that's it!