To mirror the existing git repository (i.e, src-repo) into another git repository (i.e., dest-repo), follow the steps given below:
- Create a bash file and name it as mirror-sync-repo.sh
- Copy the below code and paste it in your bash file
- Modify the code by replacing pseudocode with the actual repository names and links
- Save the bash file
- Open the Terminal app and go to that folder where this bash file is present
- Execute the bash file on Terminal using
sh mirror-sync-repo.sh
command, you'll be asked to enter the username and password for both the repositories; just enter that and let it proceed - One the execution is finished, both the repositories are mirrored and synced
#!/usr/bin/bash
SourceRepositoryURL=http://src-repo.gitserver1.domain
DestinationRepositoryURL=http://dest-repo.gitserver2.domain
SourceRepositoryDir=src-repo.git
if [ ! -d $SourceRepositoryDir ]
then
git clone --mirror $SourceRepositoryURL
cd $SourceRepositoryDir
git remote add --mirror=fetch secondary $DestinationRepositoryURL
cd ..
fi
cd $SourceRepositoryDir
git fetch origin
git push secondary --all
Comments
Post a Comment