Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advice for using Git to manage website development?

Tags:

git

deployment

I'm a designer that's looking to ease the pain of managing the development of my websites. I've only recently discovered Git and so far it has been very easy to pick up. From my understanding it is possible to use Git as a way of deploying these changes using two or more repositories; one of which is the master. I'm specifically interested in having a development environment, a testing environment and a production site.

So I have a few questions:

Is it acceptable to use Git in this way?

Which is better; storing the master repository on your local machine and pushing changes to the production and testing server? Or is it better to store the master on your production sever and pull to your local machine to make changes?

If so how would you accomplish either method?

like image 250
limitlessloop Avatar asked Feb 07 '11 14:02

limitlessloop


2 Answers

There might be a little bit of confusion here so i'll try to clarify things.

A repository is just a copy of your code. You can have several copies of your code (that is, several copies of your repository, for example: One on your development machine, one on your testing server, and one on your production server). Everything is coming from the same code, you just could have each repository at different commits (a set of changes) or a different branch.

My suggestion would be to work like this. You create a repository with your code by doing in the root directory of the project you want to version with git.

git init

Now, you can create several branches of your code. One would be called "master" (this is usually how people name it) and it is used to store production code. Another branch can be called "development". So, when you are going to start playing with your website, you switch to development branch in your local copy of your repository, make the changes, commit to that branch, and push those changes to the repository in your test server (which you would usually keep set in the "development" branch). You test your code, and then when you feel it is ok, you merge your development changes to master, and then push that to your production server repository (which would be usually in "master" branch).

I would strongly suggest that you use github.com, it could really simplify things and also help you to keep remote safe copies of your code. Also, you don't need to create git servers to be able to push changes to each copy of your code but you just update your github copy, and later you can pull those changes from each version of your code (i.e testing and production).

All i explained here could be a little bit confusion, you can check a book to understand the difference between a repository itself and a branch in a repository. Git is a great choice to keep your code organized. If you decide to go with it, you could take a look at this site http://gitimmersion.com/

like image 136
acadavid Avatar answered Sep 26 '22 02:09

acadavid


It's a great idea to use Git like this. From what I've seen, most people have the master on their local machines and push to a production/testing server.

There's a nice guide to using Git for this purpose here: http://toroid.org/ams/git-website-howto

If you want a testing machine as well, do the steps described in 'The remote repository' again on a different machine and add it as a remote with a different name.

like image 36
ns476 Avatar answered Sep 24 '22 02:09

ns476