1

We had a number of developers working on a large website project using Git. We have a GitHub repository and then we have the website on the server, plus all the developers have their local versions.

When we finally launched the project, I got lazy (hangs head in shame) and started making changes directly to the server, without pushing them back to the Github repo. However, other people made changes to the repo, for reasons I don't quite understand, that were never pushed down to the server and are now either outdated or wrong. We have been doing this for almost seven months.

Now the server and repo are hopelessly out of sync. I would now like to get the most updated version of the site (which is the server) back up to the Git repository so we can begin another round of development. I basically want to start with a fresh copy of what is on the server.

How would you recommend I proceed? That was the first time I had used Git. It didn't seem like such a big deal at the time but now seems like it is harder to start up again than I thought.

I have looked for instructions and don't really see anything that fits. Because I am not super confident in my Git skills, I am afraid to just start trying the few ideas I did find and losing what I have on the server.

(I know I could restore from a backup if I really messed it up but would prefer not to do that as it would take the site down.)

Can I uninstall git and start again with a fresh repo? Or is there a safe way to push the current version up to the repo?

Thanks for your help.

UPDATE: I found this answer elsewhere (Replace GitHub repo while preserving issues, wiki, etc) but I am not sure how to do this:

  • cd into "new" repository
  • git remote add origin git@github.com:myusername/myrepository (replacing myusername & myrepository accordingly)
  • git push --force origin master
  • Possibly delete other remote branches and push new ones.

Not sure what they mean by "new repository"

Community
  • 1
  • 1
  • What's the problem about uploading the current server code straight to github? – Wagner Leonardi Nov 13 '13 at 19:28
  • Just push the latest one to the existing repo? – Rivasa Nov 13 '13 at 19:30
  • I updated my question to include the fact that changes were also made to the repo that i do not want on the server. I have no idea which of those changes are good code and which aren't. So, basically, I don't trust anything in the repo. I want to start fresh. How do i do that? – user2989206 Nov 13 '13 at 19:42

2 Answers2

1
  1. Make a new branch and push it to GH.
  2. Make a new branch based on the previous branch.
  3. Switch to the new branch (created on #2).
  4. Delete all the files and folders on this branch repository except the .git folder and contains
    (maintain the README.md, .gitignore and other files if you want it).
  5. Copy all the files from the server except .git folder.
  6. Commit.
  7. Switch to local Master (created on #1)
  8. Merge this new branch with the previous one.
  9. Solve conflicts
    (I use SmartGITthat have a visual conflict solver and helps me a lot, but you can use gitdiffif you don't want a visual interface)
  10. Commit
  11. Push it to GH.

I hope this helps

jkutianski
  • 580
  • 6
  • 16
  • Couple questions: what is the purpose of the two branches in steps #1 and #2? Also, shouldn't there be a merge with original in there somewhere? Or maybe delete the original original branch master? Finally, why would there be conflicts if they are all branches of the same original? Thanks. – user2989206 Nov 13 '13 at 22:13
  • If you make somthing wrong on this branch you can delete it and you've a second local copy and you can start again. And the merges are on the local branches on this way. Don't delete the original branch. You can delete the second local branch after pass #11. The second branch after the #5 had new files and differ from the original (if you change something). If isn't clear the branch on #2 is a branch of the master local branch. – jkutianski Nov 26 '13 at 20:20
0

I figured this out. What I did was:

  1. Make a new branch on Github to effectively store a backup.
  2. $ git add . to stage all changes
  3. $ git commit -m "Commit message" to commit changes
  4. $ git push --force origin master to force changes from server to remote branch master

Once I did this, there were still hundreds of files I had deleted on the server that were not reflected on the remote github.com repository. I used the following:

$ git rm $(git ls-files --deleted)

See Removing multiple files from a Git repo that have already been deleted from disk

Then repeated git commit and git push. Now my github repo matches my server exactly.

I have not yet deleted the "backup" branch I created on github but I will.

Hope that helps someone.

Community
  • 1
  • 1