Git as deployment tool

1 min.

This is the simplest way to setup a push-to-deploy system. You do not need any scripts, services or version control hosting to make it work. You just need to have ssh and git on your machine and server.

Run these commands on your remote server, in the folder you wish to deploy:

git init --bare
git config receive.denycurrentbranch ignore
echo "git checkout -f" >> .git/hooks/post-receive
chmod +x .git/hooks/post-receive

Now run this in your local repository:

git remote add server ssh://[email protected]/var/www/
git push server master
git push --set-upstream server master

That's it! Just push your changes to remote and they will be live. You can set any commands to be executed after deployments in .git/hooks/post-receive.

Do you have comments? Tweet X it at me.

Keep up with me

Consider subscribing. There's also an RSS feed if you're into that.

Wanna reach out? Tweet at me or drop me a line: golb [tod] sadat [ta] olleh.

Est. 2011