I’ve used this setup so many times now that I wanted to write up a list post explaining how I do it. This method is something I found on this site, but I just wanted to add my own commentary.
The idea is that you are developing a website locally using git, and you want to be able to easily push to your live site with git. We will set up a remote repository on your server, and push to it.
Let’s say you have your local repository already set up. Log on to your remote machine. Navigate to a directory where you want to keep your repository. This does not necessarily need to be the same location as your code, and you actually probably want it to b e a different place.
### On the remote machine corn03:/afs/ir/group/paperless2> mkdir repo.git && cd repo.git corn03:/afs/ir/group/paperless2/repo.git> git init --bare Initialized empty Git repository in /afs/ir.stanford.edu/group/paperless2/repo.git/
The way this is going to work, is that we are going to create a post-receive hook. A post-receive hook means you can run some script after this repo has received a push. What we are doing here is checking out the current gode to some directory, which we define as the GIT_WORK_TREE. You can make the GIT_WORK_TREE wherever you want. Then we make the script executable.
corn03:/afs/ir/group/paperless2/repo.git> cat > hooks/post-receive #!/bin/sh GIT_WORK_TREE=/afs/ir/group/paperless2/cgi-bin git checkout -f corn03:/afs/ir/group/paperless2/repo.git> chmod +x hooks/post-receive
Now, on your local machine, add the remote you want to push to. On this first one, make sure you include the branch you are including, like master.
## Locally > git remote add web ssh://jkeeshin@corn23.stanford.edu/afs/ir/group/paperless2/repo.git > git push web master
For any future updates
> git push web
It’s pretty basic, easy to use, and works for lightweight deployment for a site by yourself or with a few other people.
The only issue I had was one time, my internet connection went down in the middle of deployment and the git process crashed. Then the next time I tried to push, nothing happened. After a little bit of searching, the fix was that there was a file “index.lock” that was created, and once we removed that file, it worked again.
