It’s about time that web designers, not just developers, start using version control, and while staying as far as possible away from the SVN vs. Git battle that still rages on, I just use Git and pretend like SVN never existed.
We use media temple to host much of our clients work and stage up changes and updates to sites before we push them live to one of our application servers or perhaps its final destination is on the (gs) server itself.
Luckily if you are on a Media Temple (gs) you already have it installed. So besides the server you’ll need:
- Mac OS X Leopard or Snow Leopard (or Linux)
- Git 1.5.6 or higher
- A sprinkle of Terminal and SSH knowledge
Firstly, I’ve created a domain git.mydomain.com, You can use any subdomain, but this seems to make the most sense.
# navigate to where you keep your projects
cd ~/Projects/
mkdir my-website
cd my-website
git init
touch .gitignore
git status
git add .
git commit -v -a -m "initial commit"
So we’ve created a local repository on our computer, which is already useful in terms of some basic version control! But there are a few more things we should do before we can make real use of our new repository.
With the empty .gitignore file (which is necessary because git needs at least one file in the repository, folders don’t count) we can tell git which files not to put in the repository, mine looks like:
.DS_Store
log/*.log
tmp/**/*
So this one is more setup for a rails app specifically the last two declarations, feel free to edit them and keep the files you want out of your repos. Remember some files especially logs can grow really large over time and they also don’t have a purpose in your repository
cd ~/Projects/
git clone --bare my-website my-website.git
touch my-website.git/git-daemon-export-ok
Uploading the repository to our server, scp is a great protocol for transferring files, but you can also use rsync or even [shudder] ftp.
scp -r my-website.git serveradmin%s#####.gridserver.com@s#####.gridserver.com:domains/git.mydomain.com/html/my-website.git
Now you can pull files from your repository, but first clone your repository and you’ll have a local copy of it.
git clone http://git.mydomain.com/my-website.git
After making some changes or adding files you can commit them them like you did earlier.
git commit -a -m "just added some features... blah blah"
lastly, you can push them to the repository using git push, telling git to send the master branch
git push ssh://serveradmin%s#####.gridserver.com@s#####.gridserver.com/home/#####/domains/git.mydomain.com/html/my-website.git master
Because it sucks to type that every time you want to push your changes Git allows you to have have multiple tracked repositories. Since we cloned our project from http://git.mydomain.com/my-website.git Git knows it can just push to there every time. Let’s add a remote repository and tell Git to push our changes there.
cd ~/Projects/my-website/
git remote add gridserver ssh://serveradmin%s#####.gridserver.com@s#####.gridserver.com/home/#####/domains/git.mydomain.com/html/my-website.git
Great! Now you can push changes to your Grid Server just by running git push gridserver master.