简体   繁体   English

使用一个远程服务器管理两个本地GIT仓库

[英]Managing two local GIT repos with one remote

I have ended up with quiet a mess with my github repo, and I am looking for some advice on how to sort it out and prevent it from happening again in the future. 我最终对我的github存储库感到一团糟,并且我正在寻找一些有关如何整理它并防止将来再次发生的建议。 I will start by saying I am a systems guy not a developer, but I am responsible for managing the repos. 我首先要说我是系统人员,而不是开发人员,但我负责管理存储库。

My environment looks like this: 1 Development server, 1 production server, and 1 github repo. 我的环境如下所示:1个开发服务器,1个生产服务器和1个github存储库。

My current problem is: Both dev and production servers are using the same github repo. 我当前的问题是:开发服务器和生产服务器都使用相同的github存储库。 One of our developers has pushed code directly into the github master, which is currently running on the dev server, in the mean time changes have been made locally to the prod server. 我们的一位开发人员已将代码直接推送到github主服务器上,而github主服务器目前正在开发服务器上运行,与此同时,对prod服务器进行了本地更改。 The new code on the dev/remote is not production ready and I need to get the local changes from production into github and deployed on the dev server without overwriting the new code on dev. dev / remote上的新代码尚未投入生产,我需要将生产中的本地更改放入github并部署在dev服务器上,而不会覆盖dev上的新代码。

I think the solution to prevent this from happening again is the make the developer use branches instead of pushing into the master, and not making anymore changes locally on production. 我认为防止这种情况再次发生的解决方案是使开发人员使用分支而不是推入主服务器,并且不再在生产环境中进行本地更改。 Any tips or advice is greatly appropriated. 任何技巧或建议都非常适合。

The easiest solution is to create a new branch, called production , pointing to the commit you want to be deployed on your production server, then check out that branch on the production server. 最简单的解决方案是创建一个名为production的新分支,指向要在生产服务器上部署的提交,然后在生产服务器上签出该分支。

Developers are then free to push to master which is the default branch on Git. 然后,开发人员可以随意推送到master ,这是Git上的默认分支。 To update the production server to a newer version of the code, you can advance the production branch to the commit you want to deploy, push production to GitHub, then do a git pull on the production server. 要将生产服务器更新为代码的较新版本,可以将production分支前进到要部署的提交,将production推送到GitHub,然后在生产服务器上进行git pull

You can configure GitHub to put restrictions on the production branch so that developers can't push to it, and only allow authorized people to modify that branch. 您可以配置GitHub以对production分支施加限制,以使开发人员无法推送到它,而只允许授权人员修改该分支。

To sort out the current mess: 整理当前混乱情况:

  1. Get the code from the prod server pushed to GitHub. 从推送到GitHub的产品服务器中获取代码。 Since master currently has other stuff in it, we'll push to a new prod branch. 由于master目前还包含其他内容,因此我们将推到新的prod分支。 On the prod server: 在生产服务器上:

    a. 一种。 git checkout -b prod to create a new prod branch. git checkout -b prod创建一个新的prod分支。

    b. git commit to commit your changes to the local prod git repository. git commit将您的更改git commit到本地prod git存储库。

    c. C。 git push -u origin prod to push your code up to GitHub. git push -u origin prod将您的代码推送到GitHub。

  2. Now let's get that merged into master. 现在,让我们将其合并到master中。 On the dev machine: 在开发机器上:

    a. 一种。 git checkout master and git pull to make sure you're up to date. git checkout mastergit pull确保您是最新的。

    b. git merge prod to merge the prod branch into the master branch. git merge prod将prod分支合并到master分支。

    c. C。 git push to push the merged master branch up to GitHub. git push将合并的master分支推送到GitHub。

  3. Now, you're left with a prod branch that represents production and a master branch that contains all your changes. 现在,剩下的是代表生产的prod分支和包含所有更改的master分支。 It's up to you if you want to rename these, continue dev work on master, push master to prod, or whatever. 是否要重命名这些名称,继续在master上进行开发工作,将master推送到prod等等,完全取决于您。


How to avoid this in the future: 将来如何避免这种情况:

  • Never edit code on a production box. 切勿在生产盒上编辑代码。
  • Any code that gets pushed to production should be tagged with a release version. 任何推送到生产环境的代码都应标记有发行版本。 If you don't have a versioning scheme, you should start. 如果没有版本控制方案,则应该开始。 It doesn't need to be fancy - you can just start with 1 and go up from there if you want. 不需要花哨的-您可以从1开始,然后从那里开始。
  • Implement a release process. 实施发布过程。 For example, master should contain only tested code that's ready to be released. 例如,master应该只包含准备发布的经过测试的代码。 And when the code is released, master is tagged and then the tag is deployed to production. 并且,在发布代码时,将对master进行标记,然后将该标记部署到生产环境中。 Or something like that. 或类似的东西。 Figure out what works for you. 找出最适合您的方法。
  • In conjunction with the release process, develop policies around where code should be pushed. 与发布过程结合,制定有关应将代码推送到何处的策略。 Most organizations would have devs push to a branch like feature-a and then open a pull request to master once the code is tested and ready to go out. 大多数组织会要求开发人员将其推入feature-a -a之类的分支,然后在测试代码并准备就绪后打开拉取请求以掌握。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM