Pages

Friday, October 18, 2019

How to create mirrored repositories and keep it synced?


To mirror the existing git repository (i.e, src-repo) into another git repository (i.e., dest-repo), follow the steps given below:
  1. Create a bash file and name it as mirror-sync-repo.sh
  2. Copy the below code and paste it in your bash file

  3. #!/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
    

  4. Modify the code by replacing pseudocode with the actual repository names and links
  5. Save the bash file
  6. Open the Terminal app and go to that folder where this bash file is present
  7. 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
  8. One the execution is finished, both the repositories are mirrored and synced

No comments:

Post a Comment