简体   繁体   中英

How to make two git repositories identical?

Scenario:

I have two git repositories called, volatile and template respectively.

template is a Read-Only repo that is treated as the "original".

Both volatile and template exist on multiple (atleast two) upstream remotes.

volatile starts out as an identical copy of template . This is done by force pushing to volatile from inside template like so:

cd template;
git push -f remote-url1:volatile --prune
git push -f remote-url2:volatile --prune

After a few operations on volatile, the state of volatile changes. Branches, tags and commits are added.

How do I go about making volatile identical to template (on the remotes) again?


I can currently reset branches by doing the following:

 # On my local machine
cd template;
git push -f remote-url1:volatile 'refs/remotes/origins/*:refs/heads/*' --prune
git push -f remote-url2:volatile 'refs/remotes/origins/*:refs/heads/*' --prune

I've tried using

cd template;
git push -f remote-url1:volatile --tags --prune

and

cd template;
git push -f remote-url1:volatile --prune 'refs/tags/*:refs/tags/*'

to remove tags added on the remote, but this seems to give mixed results (I can't delete tags at times, remote says everything is up to date)

So far, the best bet seems to be:

cd template;
git push -f remote-url1:volatile 'refs/remotes/origin/*:refs/heads/' --prune
git push -f remote-url1:volatile '+refs/tags/*:refs/tags/*' --prune

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM