Do web development, used to write a new feature to publish to the server is the use of FTP upload overwrite the original code, this is very troublesome, first to open the FTP program, then enter the specified folder, and then upload, And with FTP upload often error always have an individual file due to permissions or a variety of wonderful reasons upload failure ... There's no such thing as using Git to deploy.
If your project is a team doing, you may also need a public repository such as GitHub or gitcafe,git.oschina.net,git.csdn.net to use them to deploy to remote servers as well. By setting up hooks such as GitHub (a domestic git site called push hooks), the function is that each time we change from local push to these warehouses, these warehouses will have a POST request to the specified connection (for example, their VPS server) (more than one request, but a common post request, The content of the request is also different from the warehouse, we can set our own VPS production server once received this post request to start deployment, can write bash script or Python script implementation, or directly online to find someone else to write.
Another way to do this is to use a VPS production server to do these things (code management + deploy the production environment code) instead of using a public repository for hooks, and then discuss how to do so.
Create your own warehouse
Cd/varmkdir git && cd gitmkdir your_site.git && CD your_site.gitgit init--bare
--bare means that this folder is our code warehouse, it will not release the source code and just do version control.
Hook Hooks
We will use post-receive hooks, more hooks and meanings to refer to git documents in the Your_site.git folder
Ls
You can see that the Hooks folder has been created for us, and there are also examples of various hooks inside.
CD hooks
Create our own post-receive
Cat > Post-receive
Press ENTER after prompting us to continue the input, the next input will be placed in the Post-receive file.
#!/bin/shgit--work-tree= Production Environment Web site folder location--git-dir=/var/git/your_site.git checkout-f
After the input is completed, press Save, referring to the address of the warehouse, is the location of the ctrl + D
git-dir
work-tree
code, that is, the location of our site's source code. The next step is to make sure it works:
chmod +x post-receive
Local
The general situation is that you already have your own Git project, then you just need to add the VPS warehouse address on the line
git remote add myvps-sitename ssh://[email protected]/var/git/your_site.git
' Myvps-sitename ' is just the name of this remote connection, you can have multiple remote connections at the same time, specify a name each time you push to upload code to a different repository.
If you do not have a project code locally:
CD Project address git init
After you add a readme.me file
git Add. Git commit-m "project start"
Then we can push the code to the VPS:
git push myvps-sitename Master
master
The master branch is specified, and you can push other branches if you have other branches ...
Use git to deploy Web site code to the production environment VPS