Heidel
Heidel

Reputation: 3254

Sync git repo with server changes

I have a project in a repository.

A programmer (not Me) changed the deployed code on the server directly instead of editing the Git controlled repository (a lot of changes have been made).
So now the repository has an old version of code.

What should I do in this case?

Should I create a new empty branch, copy the code from server there and then make this branch master like it's described here?
Or something else?

Upvotes: 0

Views: 275

Answers (1)

Matt S
Matt S

Reputation: 15364

I think the first priority is to get that code into git. I would treat the code that's in production as new development work.

  • Create a new branch off of your current master / development branch. Assuming your server is a checkout of the master branch:
    • git checkout -b prod-edits origin/master
  • Commit the production edits into that branch just like typical code changes.
    • git add -A
    • git commit -m "Production edits"
    • git push origin prod-edits
  • Then I would go through whatever workflow you normally do for feature branches, e.g. merge into a test branch, QA it, merge into master.
  • Next step is launching. If you launch "by hand" by pulling down master directly onto the server, I would remove the edits and download the latest. This is the destructive step that will change your code in production, so do this in a copy of the directory and symlink back to it after it's complete. Have a backup ready. Something like
    • cp -r /path/to/code /path/to/current
    • cd /path/to/current
    • git reset --hard && git pull
    • rm -fr /path/to/code && ln -s /path/to/current /path/to/code

Upvotes: 1

Related Questions