tags:

views:

67

answers:

1

Hi Guys,

We are migrating from HG to Git. Our set up is like so:

Dev locally, commit and push the code to our dev server and test, then we take the code on dev and put it on prod. So, : local -> dev server/staging -> production server

How we do this with HG is the following:

From local to devserver

hg commit -m 'stuff'
hg push ssh://user@devserver//var/django/projects/project_name
ssh -l username devserver 'hg update -R /var/django/projects/project_name

From devserver to production Login to server

mkdir /var/django/projects/project_name ; cd var/django/projects/project_name ; hg init
hg pull ssh://username@devserver//var/django/projects/project_name
/etc/init.d/apache reload

I am trying to replicate this same thing with Git but have had no luck with getting these to work. So far what I've tried to do was:

Local

git init
git add .
git commit
git remote add origin ssh://user@devserver/var/django/projects/project_name
git push origin master

Dev Server

git init

(source code lives here for testing)

Production server

git init
git remote add origin ssh://user@devserver/var/django/projects/project_name
git pull origin master

Problem is the git way I am doing it is not updating the production server with the latest committed changes

Any ideas how I can do this type of workflow?

Regards,

Jeff

A: 

It appears as though your dev server is a "non-bare" Git repository (meaning it has a working copy). See this question for a related scenario: Git push only for bare repositories?

When you pushed into the dev server, you may have received a warning stating that pushing into a non-bare repository is unsafe and probably not what you want. What I would do is set up a new bare repository (using git init --bare) for development staging. It doesn't matter where this repository is (as long as it's accessible from all your servers). Then, after pushing your code to the dev repository, log in to the the dev machine itself and pull from the bare dev repository to update the local files to the latest code.

When you want to update your production server to a specific version of the code, log in to the production server and pull from the repository to update the production files. You can even check out a specific version (by SHA1 hash or tag or whatever) to make sure that you don't get any other commits anybody else has pushed into the repository in the meantime. (This would also allow you to roll back to any previous version at any moment if you need to.)

The above workflow also easily supports more than one development server.

Greg Hewgill
Hello Greg, thanks for answering, I have tried to do this way, my problem is when I log into the dev server to do the pull I get this error: fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
JeffTaggary
@JeffTaggary: To clarify, you would create one bare repository somewhere (it could be on the dev server, but certainly doesn't have to be), where you *push* your changes to. Then using `git clone` on the dev server, create a clone with a full working copy that you actually use for development testing. From that clone, you then `git pull` from the master repository (the bare one). You would do something similar on the production server, for example pulling a particular tag from the master repository.
Greg Hewgill