tags:

views:

124

answers:

2

I understand the basic and how the workflow works and what not. However, let's say I have a local repository on my linux workstation. Now, I also have a production box located on a VPS in a remote DC. If I wanted to push out new code to the production box, what's the best way to do so? I don't want to have a Git repo on the box, it should just have my web code (php/mysql).

How does one push out the new changes to the production box w/o sending over ALL the files?

+4  A: 

One way to manage web content is to create a "bare" repository on the production box. This is a repository that doesn't have a working copy. When you want to deploy new code, you would push to this repository to update it. Then, log in to the production box and pull from the bare repository into your actual deployment directory (which is also a Git repository).

Note that neither of these repositories on the production box need to be considered the "master" repository; you can keep your source code elsewhere and just push to production as needed.

The reason you need two repositories is that Git does not support pushing directly into a repository with a working copy. Git has historically allowed you to do this (often with unintended consequences) but newer versions strongly encourage you to avoid pushing in this way.

I use the above technique to manage some web sites and it works really well. One benefit is that if I really need to, I can patch something on the production machine, commit it right there, then later on pull that change into my development repository. Changes made in this way are much less likely to get accidentally lost.

Greg Hewgill
Ok, so I don't have to open up any ports on my local workstation where the main repo is, correct? I'm pushing from local to "bare" repo on production via ssh and then log into production on VPS and run a pull form the "bare" repo.
luckytaxi
That's exactly right.
Greg Hewgill
+1  A: 

So I think you may have a misconception on how repositories work, your repository can be anywhere you want... it doesn't really matter, it can even be on github, or the VPS. The basics are that while you are working you make commits, (with git these are made to a local repository) and when you are ready to apply those changes you "push them", this will send the deltas (only the changes made to your code).

When you are ready to make the changes live on your production box you'll login to your sever and pull the changes from your repo and deploy (which may include restarting or migrating your database... this is usually refereed to as a recipe)

Joseph Silvashy
i got that, i just needed help understanding how to get production to mimic what was in HEAD. I didn't want to open up ports in my firewall so i can grab the delta from my local workstation.
luckytaxi