1

I am a newbie at Git and really need help in trying to solve this, as I am totally confused as to how do so.

Let's say I have two repos in Github, Repo1 and Repo2. Repo1 is my personal Repo and contains a piece of software. Repo2 is part of something else and contains the same contents as Repo1 (it's a branch).

Some time ago I managed to mess up Repo1, and also managed to update Repo2 with the incorrect information. In my attempts to fix both, I did successfully fix Repo1, but forced an update of Repo2 with the files from Repo1 (using Github for Mac) which updated Repo2 with the correct files but totally messed up Repo2's history.

Now I can update Repo1 properly, but whenever I try to fetch the files in Repo1 (upstream) to my local Repo2 I get merge errors. I tried using the solution given here: Resolve conflicts using remote changes when pulling from Git remote This appears to fix the local Repo2 (but I'm not sure...), but when I try to push the results to Repo2 on Github I get the following error message:

! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/folder/Repo2.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I do not care about the history in Repo2; I just want to overwrite the whole contents of Repo2 with the contents of Repo1 and be rid of any subsequent problems. How can I do that?

Please help, as I find dealing with this entire mess extremely frustrating and I am not sure what I am doing.

Community
  • 1
  • 1

2 Answers2

2

If you just want to get your whole contents of repo1 at repo2 you could try:

git push --mirror

you can find this in the github help pages

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
0

It seems Repo2 on github is ahead of your local version of Repo2. You'll need to either fetch and merge or fetch and rebase from github in order to push to it again.

JBarberU
  • 999
  • 8
  • 16
  • Yes, and that is something else I do not understand. The files currently in Repo1 are a week younger than those in Repo2. What I think happened when I forced the Repo2 update is that the two branches started to diverge, so if I understand the current situation correctly I would have to get Repo2 back to the last commonly shared state with Repo1 before I can update Repo2 with the newest files from Repo1. Surely there is a simpler way to resolve this problem? – user2982631 Nov 12 '13 at 10:46
  • Okay, so using http://stackoverflow.com/questions/4114095/revert-to-previous-git-commit (first answer, third option) and http://stackoverflow.com/questions/1616957/how-do-you-roll-back-reset-a-git-repository-to-a-particular-commit I've now managed to revert both the local and Github versions of Repo2 to an earlier state shared with Repo1. However, if I now try to fetch the latest batch of files from Repo1 and push those to Repo2 I'm happily told 'Everything up-to-date' while that is not the case. *Sigh*. Why is it so easy to break things in Git and so difficult to fix them? – user2982631 Nov 12 '13 at 15:32
  • I ended up taking my regular back-up of the files and copying the latest versions of the files off that into my local repository for Repo2, then committing and pushing that. I'll try to resolve the remaining problems later. Anyway, thanks for the suggestions. – user2982631 Nov 12 '13 at 16:15