[英]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: 整理当前混乱情况:
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。
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 master
和git 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。
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: 将来如何避免这种情况:
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.