After trying out a few different options, I finally came up with an easy way to move files to the server using git. This isn’t using GitHub at all, but actually a Git repository on our server. It’s nice and you never have to use FTP or SCP, just some shell commands for the initial setup! The setup might seem a bit daunting but it’s not that hard and you’ll have it running in no time. It may ask for your password a few times in the commands, keep in mind when you’re typing characters they won’t show up when doing the password. This is for security purposes, of course.)
SSH into the server, Windows users can use puTTY, OS X and GNU/Linux users can use the ssh command like this:
ssh user@server.internet.com
(obviously replacing user with your username and server.internet.com with the server)
Then do the following commands: (replace web with what you want to call the repo if you want to call it anything else. web is perfectly ok though.)
mkdir web
cd web
git init –bare
cd hooks
touch post-receive
nano post-receive
This will open a text file to edit. You can use a text editor of your choice instead of nano, but I think the server only has nano and vim. Vim is what I’d recommend using if you know how, but if not nano is perfectly O.K. Here’s what you need to fill the file with:
#!/bin/bash
GIT_WORK_TREE=~/html/ git checkout -f
echo Updated Successfully
After that save the file and exit (I think it’s CTRL+X with Nano, and :wq on Vim). Then you will be all set with the server. After this you need to clone the repo. I’m not sure how to do this properly on Windows, but for the OS X and GNU/Linux users you do the following command:
git clone user@server.internet.com:web
(where user is your username and server.internet.com is our server. web is the repo)
This will clone the repo to your machine. It’s going to be empty, so it’s time to fill it with things. I’d test it first, by putting an index.html file with some stuff in it in the folder, and then adding, committing, and pushing. (If you don’t know the commands, they’re:
git add -A
git commit
git push origin master
git add -A adds every file in the folder, so watch out) Then the server should be updated. Put the server address in an address bar and head to your user folder and your files should now be there. They’re also tracked by git so if you’re familiar with git you can revert changes and all that fun stuff.
Hope this is helpful to some people. I’d recommend doing this over the other options as this’ll help get you familiar with git and it’s also much simpler to do after the initial set-up.
From the blog Five mvs of Doom by Chad Wade Day, Jr. and used with permission of the author. All other rights reserved by the author.