Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Automatic Git deploys on Dreamhost
# Replace this line with your real domain name
echo "-= Transferring changes to $DOMAIN =-"
# Clearing git env
unset GIT_DIR
cd ~/$DOMAIN
git pull
echo "-= Done =-"
# Replace any brackets with real values
# Try to ssh in to DREAMHOST (ensure it no longer asks for a PW); you may want to restart Terminal
ssh [user]@[host]
cd ~
mkdir [mydomain_com].git
cd [mydomain_com].git
git init --bare
vi hooks/post-receive
# Enter the code from the "post-receive" file (in this gist); save + quit
cd ..
git clone [mydomain_com].git []
# Add remote to git's list of remote repos
cd [some local git folder]
git remote add live ssh://[user]@[host]/~/[mydomain_com].git
# Push to production :)
git push live master
# Replace any brackets with real values
# Before you start this, ensure that you have added shell (ssh) access for your hosted account (not just sftp/ftp).
# You may need to generate a new ssh key; if so, follow instructions to generate ssh key
ssh-keygen -t rsa
# Add to authorized keys on DREAMHOST
# For OSX:
cat ~/.ssh/ | ssh [user]@[host] "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
# Else:
ssh-copy-id [user]@[host]

stinoga commented Mar 3, 2012

Awesome Jake. Got this working on an amazon bitnami setup tonight. The only part I can't get working is the post-receive hook. The file doesn't seem to be firing off, and I have to run a manual pull request on the server.

stinoga commented Mar 3, 2012

Also, had to run "git push live master" for some reason. Got errors if I didn't.


jswartwood commented Mar 3, 2012

Right... that was where I was leaving a placeholder for "production" vs "staging" tags; changed gist.

You may need to adjust perms on post-receive (via chmod). Does it have "x" if you ls -al?

stinoga commented Mar 6, 2012

Yep. chmod 755 post-receive did the trick. I also had to add sudo to the git pull line. It didn't like the permissions either.


jswartwood commented Mar 6, 2012

You may be able to change owner (chown) to avoid sudo, but if it works so be it.

Also, not to quibble over usage of chmod, but in case you aren't familiar w/ the other syntax... I find the chmod [scopes][+-][perms] variant more "user-friendly" if you aren't a unix guy. Ex: chmod ug+xw post-receive will add (+) execute (x) and write (w) privileges for the user (u) and (g) of the file.

The drawback is to do chmod 755 post-receive, you would need at least two commands chmod a+rwx post-receive (add all perms for all users) and chmod go-w post-receive (remove write perm for groups and others) to ensure the end result of 755.


ghost commented Aug 18, 2014

Thank god for you. I've been pulling my hair out over this for days. Worked like a charm with the chmod 775. No need for sudo on my end.

Great stuff man!!! Thank you very much for this!

THANK YOU! This is brilliant - I needed to chmod 755 post-receive to get it to work.

Thanks!! Any idea why it doesn't work with method of setting the work tree of the bare repo?

jbond84 commented Dec 1, 2015

Not sure if this is still working, I have setup the identical configuration with my sites domain and I get the following error:
remote: -= Transferring changes to =-
remote: fatal: Not a git repository (or any parent up to mount point /home)
remote: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
remote: -= Done =-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment