Git:localhost>远程开发>远程生产 [英] Git: localhost > remote development > remote production

查看:76
本文介绍了Git:localhost>远程开发>远程生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Git的新手,但我不明白如何实现以下目标。
有2台服务器:


  1. 本地主机

  2. Linode.com VPS

基本上,我想:


  1. 代码在我的本地主机上。

  2. 将新代码推送到VPS上的开发
    版本,可以测试
    (在dev.domain.com或类似的地方) )
  3. 如果新代码正在运行,请将
    推到
    相同VPS上的生产版本中。应该可以在
    domain.com访问。

什么是实现我想要的正确方法?

解决方案

有几种方法可以做到这一点。如果您有能力在您的VPS上运行ssh服务器,那么这非常简单。



在本地主机上的git存储库中,您将设置两个git遥控器。它们将具有相同的主机,但具有不同的路径(一个用于开发路径的远程设备和一个用于生产路径)。

  git remote add prod ssh:// [user @] host.xz [:port] /path/to/prod/repo.git/ 
git remote add dev ssh:// [user @] host.xz [:port ] /path/to/dev/repo.git/

如果你设置了ssh公钥/私钥访问那么你不必每次都输入密码。



一旦你在localhost上提交了你想要的修改到你的repo,那么你会这样做,将它们推送到开发环境:

  git push dev#remote dev dev指向开发库



验证完后,您可以将它们推送到生产环境中(从本地主机上的回购):

  git push prod#remote prod points to prod repository 

如果你打算在推送到dev和prod之间更改本地主机上的git repo(除了修复es你想申请),那么有很多方法可以解决这个问题:




  • 分支或标签在推动开发并推送之前,而不是您的主要分支(建议任何其他原因)。

  • 在本地主机上制作一个副本并推送它。

  • 分支进行更改并推送而不是主分支。

  • 登录到VPS,并将其从开发人员推到(或拉出)到prod回购站点



这不包括您的一半选择,但可能足以让人想到。


I'm new to Git and I don't understand how I can achieve the following. There are 2 servers:

  1. Localhost
  2. Linode.com VPS

Basically, I want to:

  1. Write new code on my localhost.
  2. Push the new code to the development version on the VPS where it can be tested (at dev.domain.com or something like that.)
  3. If the new code is working, push it to the production version on the same VPS. Should be accessible at domain.com.

What is the right way to achieve what I want?

解决方案

There are several ways to do this. If you have the ability to run an ssh server on you VPS then this is fairly simple.

In your git repository on localhost you will setup two git remotes. They will have the same host but different paths (one remote for the dev path and one for the prod path).

git remote add prod ssh://[user@]host.xz[:port]/path/to/prod/repo.git/
git remote add dev ssh://[user@]host.xz[:port]/path/to/dev/repo.git/

And if you setup ssh public/private key access then you don't have to type a password everytime.

Once you have committed the changes you want into your repo on localhost then you will do this to push them to the dev environment:

git push dev    # remote named dev points to dev repository

After they are verified you can then push them to production (from your repo on localhost):

git push prod   # remote named prod points to prod repository

If you are going to change the git repo on localhost in between pushing to dev and prod (other than fixes you want applied) then there are many ways to address this:

  • branch or tag before pushing to dev and push that instead of your main branch (recommended anyways for other reasons).
  • make a copy of the repo on localhost and push that.
  • branch before making changes and push the branch instead of the main branch.
  • login into the VPS and just push (or pull) from the dev to the prod repo

That doesn't cover half your options, but maybe enough to get thinking.

这篇关于Git:localhost>远程开发>远程生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆