views:

149

answers:

6

I use Git to track local changes in my PHP web applications, and I was wondering if it would be a good idea to use Git on the server as well, so that I could just use git push to deploy my changes. Would there be any pitfalls with this approach?

+3  A: 

I think this is a fine way to do it. I handle things in a similar manner, where live sites are just a checkout from the repository, and i update them as necessary.

GSto
+1. It makes things really nice if you want to check for changes on the server (all you need to run is a status command to look for new or modified files)...
ircmaxell
A: 

And online hotfixes can be pushed back to development.
Being able to do a git status on a live system can be a live saver.

Go for it!

Caveats

  • Make sure the the ".git" folder isn't accessible from the web.
  • With PHP the source code is usually present on the webserver, so that doesn't add additional risk in case the server is hacked.
Bob Fanger
Isn't that what a QA stage is for? So that you don't ever make online hotfixes? Heck most places don't even let their developers have access to the production server, yet alone fix things live... (but it is a valid point about backporting fixes)...
ircmaxell
Because after the Q)
Bob Fanger
No, but because any bug fixes are required to go through QA before being put into production (to attempt to eliminate the possibility of regressions)...
ircmaxell
+1  A: 

This seems like a nice way to do things. If you're tagging and branching properly it will enable you to quickly switch back to working versions of your site too in the event that something breaks.

signine
A: 

I would be in favor of using a technique like this if only because you can be sure anything on your deployed site is also being tracked in git. That is, it encourages a best practice and discourages ad hoc changes that aren't under source control.

For another alternative, check out this article about how Twitter uses BitTorrent to manage deployment: http://torrentfreak.com/twitter-uses-bittorrent-for-server-deployment-100210/ It's probably most useful when you need to deploy quickly across a large collection of servers.

Bill Karwin
A: 

I think its a great solution. I have been using it to deploy my website for a long time... Its nice because you can almost instantly push your changes into production just by updating the folder. I have encountered no security issues or anything with it.

Enjoy!

Aardvark
A: 

Git is fine but you can do a lot better then just using git pull. Take a look at railess deploy for capistrano.

Capistrano basically does a combination of rsync and git pull to deploy copies of your website. It supports roleback, staging and distributed deployments.

Ken Struys