简体   繁体   中英

How to make two git repos the same

I have two git repos with same code on two separate gitlab deployments. It is not gitlab EE so i dont have the mirror functionality available to me.

In the beginning I ensured that each commit is pushed to both repos but over time it got out of hands and i could do justice to this practice.

At the moment I would forcefully like to make repo1 the same as repo2 . But while doing this I seem to be stuck in a circle.

This is what I do:

$ git pull repo1 master
...there are conflicts. 
...I resolve them, add the file, then do git rebase --continue
$ git push repo1 master --now this works
$ git pull repo2 master
...there are conflicts. 
...I resolve them, add the file, then do git rebase --continue
$ git push repo2 master

After the above, I would imagine everything is ok. But now when I do git pull repo1 master , I have to do the above steps over again.

Question

Is there a way to forcefully make repo1 the same as repo2 other than deleting repo1 from gitlab and starting over?

Additionally, going forward what would be the best way to keep both repos in-sync?

Is it really necessary to have those 2 exact equal repos? If yes, it would be easier to push only to repo1 from local and then push to repo2 from repo1 (for example with a git post-receive hook)

But for now you could try force push ( git push -f ) to overwrite the commit history in repo1. (Assuming repo2 contains the "correct" history and repo1 the wrong one):

$ git pull repo2 master
... if there are conflicts, take versions from remote (repo2)
$ git push -f repo1 master

From repo1:

git remote add repo2 <path to the other repo>
git checkout master
git fetch repo2
git reset --hard repo2/master

Do this for every branch you'd be interested in making the same (probably just master and a develop branch?).

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