Take the 2-minute tour ×

My intended goal:

I maintain some files in my local computer, and I also share them with others by putting them on my website. In the past I did this by manually uploading all the files using FTP, every time I did some modifications etc. Now, I am wondering if I can use Git to help me achieve this (by "pushing" the local files to my website server). My server is hosted by Dreamhost.

First Attempt:

First, I try this tutorial. I first push my local files to my Github repo, and ssh into my Dreamhost server to git clone --bare from the Github repo. But I find that git does not transfer my files. So I ignore the tutorial.

Second Attempt:

I ssh into my Dreamhost server to clone directly from Github. My files are all transfered to the server. Then, on my local computer, I git remote add dreamhost ssh://username@mysite.com/~/my-project. Then I add some files, and commit, and git push dreamhost master. And a bunch of errors appear:


As a newbie Git user, I must have missed something. Please help!

share|improve this question
Do these files need to be under revision control or do you just need to "sync them"? –  Wyck Mar 24 '13 at 6:09
add comment

2 Answers

I'm not a huge git user, but try this:

  1. Clone both your local repo and your server's repo directly from Github.
  2. Make your modifications to your local repo.
  3. Commit to your local repo.
  4. Push to Github.
  5. Pull from Github to your server.
share|improve this answer
Thanks David. I'm wondering if there's a way to do this without Github. –  ConcreteVitamin Oct 4 '11 at 5:16
One of the two repos must be visible to the other on the network (counting NAT/firewalls/etc.). If both systems are behind firewalls/NAT, it's a tall order. You have to have something to git push from or git pull to. If you have an SSH link between them, I'm not sure why you couldn't pick one of the two to be master and push/pull as needed. But maybe I don't understand your question (or Git!). –  David Pope Oct 4 '11 at 5:19
add comment

When you are using a Git repository as a central repo (as you seem to be), you generally should not have a working directory on that repo. The reason for this is listed in the error you mentioned: pushing into a branch which is checked out can cause the working tree to become out of sync.

If the people you are sharing with can use Git, then you instead can set up a bare repository on the server, then push to it.

# On the server
git init --bare ~/project.git

# On your computer
git remote add origin ssh://username@example.com/~/project.git
git push origin master

# On everyone else's computer
git remote add origin http://example.com/~david/project.git
git pull origin master
git checkout master

If they cannot use Git, then you'll need a slightly more complicated workflow:

# On the server, once
git init ~/project
git config receive.denyCurrentBranch ignore

# On your computer
git remote add origin ssh://username@example.com/~/project
git push origin master

# On the server after each push
cd ~/project
git reset --hard

After this step, then the files should be available under /project

share|improve this answer
Thank you, Stephen! It works. So by design Git does not allow any simper solution? Though maybe make or a script can handle these tedious commands. –  ConcreteVitamin Oct 4 '11 at 5:46
@ConcreteVitamin: I don't believe so, because git won't check out a working directory from a remote repo, it wasn't designed for that. If my answer sufficiently answers your question, please mark it as accepted by clicking the checkmark to the left. Thanks! –  Stephen Jennings Oct 4 '11 at 15:19
add comment

Your Answer


