DEV Community

Sudhakar
Sudhakar

Posted on

Syncing two Git Repos (By using below commands you can move contents of one git repo to another without losing history and tags)

Cloning SourceRepo and Pushing that to TargetRepo

git clone --mirror SourceRepoURL

The above git clone command will create a directory in your local machine with the name of your repo.

Change to that directory and add a remote to the target repo.

cd SourceRepo
git remote add NEW-REMOTE TargetRepoURL

It creates a connection with TargetRepo.
Here'NEW-REMOTE' is just a name, you can give your own Name. Remember that name to sync these two repos.

git push NEW-REMOTE --mirror
It will push all folders and history of Source repo to Target Repo.

Syncing Those two Repos

After cloning source and pushing to target if you make any more changes to source simply use below two commands from the same directory to sync.

git fetch origin
To pull SourceRepo changes

git push NEW-REMOTE --all
To push(sync) SourceRepo changes to TargetRepo.

Top comments (0)