简体   繁体   中英

How can I configure git on a server with a development and production branch?

I am absolutely new to git. I'm the sole developer on a fairly large project and want to start keeping a history of code changes moving forward.

I current have a LAMP stack with many virtual hosts in Apache. To begin, I want to focus on my main site which has a development and production stack. Currently, I have two virtual hosts:

  • dev.mydomain.com
  • mydomain.com

I work exclusively in the dev.mydomain.com virtual host. I can browse to dev.mydomain.com any time to see my changes in real-time. When I'm comfortable with my changes, I run a bash script to push my changes to production.

sudo rsync -avh --delete --stats --progress /var/www/dev.mydomain.com/ /var/www/mydomain.com/ --exclude-from '/usr/local/bin/exclude.txt'

I want to imitate this idea using git.

  1. Do I install git on the actual web server which is running the sites?
  2. How can I configure git so I as I work on the site, I can still access those changes in real-time at dev.mydomain.com ?

I have read over most getting started git tutorials and I understand the basic commands to get started but it's important I keep my same production cycle. Is there a way to achieve that or is there another way that is similar?

You could have two branches (for example master and develop) and use git hooks so that when you push to master the server automatically publishes it on the vhost.

I also think that this could help you.

You install git as a client on each computer.

git depends on branches for most of what you describe.

One example workflow suitable for a solo developer is that you do you development on master and then, as needed you create branches off master reflecting the code at that point. You could call these branches something like prod_mmddyyyy if you want to track them historically by name.
You can also have 'prod' just be a branch that gets updated, eg by doing git merge master from the prod branch.
Then you can configure the 'prod' server to be using that branch for its code by git checkout branch_name You may also find
https://softwareengineering.stackexchange.com/q/111506/34069
useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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