Git: localhost > remote development > remote production

后端 未结 3 429
北荒
北荒 2021-02-03 15:51

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

相关标签:
3条回答
  • 2021-02-03 16:09

    A suggestion: (which is not exactly what you want)

    1) Use the "normal git way of working".. have a local and a remote repository.

    2) Pull the local repository code onto the VPS for testing

    3) Pull the remote repository code onto the VPS for production

    0 讨论(0)
  • 2021-02-03 16:18

    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.

    0 讨论(0)
  • 2021-02-03 16:32

    PhpStorm can automatically synchronize changes over sftp, even when you change branches locally.

    On Windows systems that is the best solution I've found so far. On unix/mac systems you can use rsync in combination with a utility that watches for file system changes.

    0 讨论(0)
提交回复
热议问题