Alex Rivera | Logout

Update website with a single command (git push) instead of FTP drag and dropping

Asked 2009-05-19T16:49:44.190
10

Situation:

  • I have a local copy of a website
  • I have a server that I have SSH access to

What do I want to do?

  • Commit locally until I'm happy with my code
  • Make branches locally
  • Have one master branch that is the one that should be pushed to the server
  • Update the website using a single command (git push origin master)

If I set up a git repo locally using git init, and then push to a folder on the server, it doesn't work. When I FTP to the server to check the files, they're actually there. When I SSH into the server and do git status, it's not clean, even though it should be since I just pushed to the server.


Steps I'm doing:

  1. Make a new folder on my computer (mkdir folder_x)
  2. Go into that folder (cd folder_x)
  3. Set up a new git repository there (git init)
  4. (git repository sets up successfully)
  5. Push the repository to the server using git push origin master (where origin is set up as user:pass@server.tld)
Edit
Report

2 Answers

1

When you push to a git repository, it doesn't update that repository's working files. Generally when you push, you should be pushing to a bare repository--- that seems to be how they intended git push to work.

For one of my (local ) projects, I wrote a script to automatically check out the latest "ui" subdirectory when I push my work to a deployment repo. It's embedded in a previous answer here: Developing Django projects using Git

You could also simply have the post-update hook on the server do a "git reset --hard master" if someone pushes an update to master, and use a non-bare repo rather than having a separate area for checked-out files.

answered 2009-05-19T18:26:52.183
0

I use the post-update hook as detailed in this FAQ entry: http://git.or.cz/gitwiki/GitFaq#non-bare

It will update your working tree if you have configured the remote repo as "bare".

answered 2009-06-03T13:34:19.780

Your Answer