1

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?)

Hoytman
  • 1,722
  • 2
  • 17
  • 29

1 Answers1

0

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/

  • but step 9 and step 3 are done on different folders. step 3 is done on a copy of the site, just to ensure that nothing goes wrong. – Hoytman Sep 11 '20 at 16:48
  • As you already have the source now fully merged in Gitlab by step 7, you should just clone it and you will have the latest version checked out into that directory with all .git entries, the history etc. – Prem Kurian Philip Sep 11 '20 at 16:52
  • Just to be clear: Git init is run ONLY once in the lifetime of a repository in git. And once that has been done, you can clone the repository in multiple computers or directories. – Prem Kurian Philip Sep 11 '20 at 16:53
  • I'm sorry for causing you confusion. the first git repo (step 3) was not created in the live production server folder in the directions. Maybe you are recommending that I do not need this extra folder? Also, there are many untracked files in the live production server folder (several gigs actually) – Hoytman Sep 11 '20 at 17:01
  • Yes, I know you that your plan is to copy the code from the production server into a new folder and that it is within this new folder that you will run git init (step 3) and then you will set up the git remote. You will also be adding all the files, committing the files and pushing them to Gitlab. So after this step, you just need to clone the gitlab repo into the production server's folder. No need to run git init again in the production folder. – Prem Kurian Philip Sep 11 '20 at 17:11
  • There are other issues the come up when you try to clone a repo into a folder that is not empty. – Hoytman Sep 11 '20 at 17:18
  • https://stackoverflow.com/questions/2411031/how-do-i-clone-into-a-non-empty-directory – Hoytman Sep 11 '20 at 17:20
  • I am sorry but I think you misunderstood me. I am not advising you to clone into the existing production server folder. When you clone, git will create a new folder with the repo files. That folder will now become your new production server folder. – Prem Kurian Philip Sep 11 '20 at 17:21
  • I think so. You said nothing of updating the server to change the folder that was being served. I feels like there a some steps missing in the description. – Hoytman Sep 11 '20 at 17:29