How to init git on a running production server and update from a remote repo

900 views Asked by At

I just got onboard with a project that has a live server that has been running for a year without git. In the past, the owner/dev made all code updates personally without version tracking. Then he started using git (with a gitlab account) for tracking his changes (but not for pushing changes to the server.) So before I got there, the manager added a copy of the site to gitlab, and started creating issues and feature branches. Now, he wants to start using git to push code changes to the production server. We have two issues:

  1. The live production server folder does not contain a git repo.
  2. After starting the gitlab repo, some of the files in he live production server folder were modified to fix bugs.

I need to add a git repo to the live production server folder, Merge all the code on live and on the remote, and push a production branch (with all of the features and production bug fixes) without breaking the site.

Here is my procedure so far:

  1. Create a copy of the live production server folder.
  2. Copy the .gitignore file to the new folder from gitlab.
  3. Init a git repo in that new folder.
  4. Set up a remote, pointed at gitlab.
  5. Add and commit and push that branch to gitlab.
  6. Compare the files (between pushed branch and the main dev branch in gitlab.)
  7. Create an up-to-date production branch in gitlab with all fixes and updates.
  8. Copy the .gitignore file to the live production server folder.
  9. Init a git repo in the live production server folder.
  10. Add and commit
  11. Checkout and track the production branch in gitlab.

Please tell me if this procedure is effective, Let me know if I should change any of it. Also, How can I minimize the change of breaking production? What potential issues should I be aware of?

In this instance, having the live site down during the day for a minute or two is not an issue, but I would still like to have some good instructions that minimize downtime.

EDIT ================

I am currently on step 5. I created the copy folder to limit the operations performed on the live production server folder. I wanted to limit changes to the live production server folder to reduce the risk that we accidentally broke the production site. In the finalized directions, creating an extra folder might be unnecessary. (or is it?)

1

There are 1 answers

9
Prem Kurian Philip On

You don't need to init again in step 9. You can just need to checkout the correct branch (the branch you created in line 7) from Gitlab.

Also 8 may not be needed as you would already have a valid gitignore file from the repo. Step 10 and 11 is also not needed as you would have got the correct version already checked out in step 9.

EDIT: It may be good to always use a release branch for what you push into production.

Please see this link for a good branching strategy to use: https://nvie.com/posts/a-successful-git-branching-model/