Git: localhost> remote development> remote production

I am new to Git and I do not understand how I can achieve the following. There are 2 servers:

  • Localhost
  • Linode.com VPS

Basically, I want:

  • Write the new code on my localhost.
  • Click the new code to develop the version on VPS, where it can be (on dev.domain.com or something like that.)
  • If the new code works, push it to the production version on the same VPS. Domain.com must be available.

What is the right way to achieve what I want?

+4
source share
3 answers

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

In your git repository on localhost, you will configure 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 set access to ssh public / private keys, you do not need to enter a password every time.

After you introduce the changes you want to make to your repo on localhost, you 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 push them to production (from your repo to localhost):

 git push prod # remote named prod points to prod repository 

If you are going to change the git repository to localhost between clicking on dev and prod (except for the fixes you want to apply), there are many ways to solve this problem:

  • branch or tag before clicking on dev and click to instead of the main branch (recommended anyway for other reasons).
  • make a copy of the repo on the local host and click on it.
  • before making changes and click on a branch instead of the main branch.
  • go into VPS and just push (or pull) from dev to prod repo

It does not cover half of your possibilities, but perhaps enough to think about.

+5
source

Suggestion: (this is not quite what you want)

1) Use the β€œnormal way git works”. You have a local and remote repository.

2) Pull the local repository code on VPS for testing

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

0
source

PhpStorm can automatically sync changes to sftp even if you change branches locally.

On Windows systems, this is the best solution I have found so far. On unix / mac systems, you can use rsync in combination with a utility that monitors file system changes.

0
source

All Articles