1

we run git and I have 2 branches: LIVE and DEV. There are 2 servers 1:LIVE and 2:DEV. They both are linked to respective remote branch.

Sometimes we need to "completely reset" the DEV server to the latest version of LIVE. I understand I can merge; I can checkout ... but the problem is that in the meantime many files 'may' have been added to DEV ... so what I would want to do is kindoff "completely wipe" DEV, load it with LIVE and send the new update to DEV remote: this way

local DEV == local & remove LIVE (exact copies) remote DEV = local DEV (and thereby now same as previous)

hmm does that make any sense?

My thinking was to

  1. Reset and sync DEV server with LIVE code? OR to overwrite LIVE -> DEV branche on remote?
    1. How do I remove all new files that are not in git? (they should be removed)

Otherwise formuluated: how do I sometimes completely reset my DEV server code/branch and make it an exact copy of the LIVE branch (no files more, no files less)

Many many ! thanks

snh_nl
  • 2,877
  • 6
  • 32
  • 62
  • Possible duplicate of [Reset local repository branch to be just like remote repository HEAD](https://stackoverflow.com/questions/1628088/reset-local-repository-branch-to-be-just-like-remote-repository-head) – Tschallacka Jun 20 '17 at 13:55
  • Maybe. But the answer below is a lot more to the point and straightforward! 10 points! – snh_nl Jun 20 '17 at 13:56

1 Answers1

1

First fetch the origin data so it's up to date

git fetch origin 

Checkout your DEV branch

git checkout DEV

Then reset it with the branchname you want it to be. Use --hard to overwrite all changes.

git reset --hard origin/LIVE

Then commit the changes

git commit -a -m "Hard reset to LIVE"

then push them

git push origin/DEV
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • if it makes you feel better, but the --hard usually does the trick for me to clean up unwanted files. Just play around, or just do a pull of your dev branch in a different folder on your pc and play around. – Tschallacka Jun 20 '17 at 14:04
  • gmmm so --hard removes files also that were created on DEV that dont exist on LIVE? This is the part I am so uncertain about – snh_nl Jun 20 '17 at 14:15
  • https://stackoverflow.com/questions/4327708/git-reset-hard-head-leaves-untracked-files-behind aparently it leaves **untracked** files behind. So if they weren't `added` and `committed` they will remain. But if you comitted them in a dev branch, they will be removed. – Tschallacka Jun 20 '17 at 15:32