Tito Miguel Costa
Refactoring ideas

Git Workflow

My way of versioning code

I've started to use Git a few months ago, letting behind Bazaar. Nothing against Bazaar, it does the work as expect, no issues, but since GitHub hosts all the projects that I care, the switch came naturally.

As long as I use a VCS, that's fine, can not image myself going back to the days where upload was done using an FTP client or even when rsync had its glory days.

At the moment, in the projects I'm involved, I'm the only developer, so it is easy to avoid conflicts and no need to generate patches. My life doesn't get much complicated.

When my project uses Symfony2, and that happens almost in every of my web projects, I initialize the project with composer and remove the original git repository and start one of my own.

# git repository initialization
$ git init

# ignore files
$ vim .gitignore

# add files
$ git add .

# first commit 
$ git commit -am "Setup for project X"

Normally the next step is to configure the server where the project will be hosted.

I created a git folder in /var and the project itself will be in /var/www.

A folder with the same name of the domain that will host the project is created in both folders.

$ mkdir /var/git/example.com

$ mkdir /var/www/example.com

Next step it to initialize a bare repository so I can upload my local project into it.

$ cd /var/git/example.com

$ git init --bare

In my local machine, I do the first push after adding the remote hosting normally called server.

$ git remote add server git+ssh://user@example.com/var/git/example.com

$ git push server master

What follows is configuration of capifony, but since I already discuss it in a previous blog post, I won't repeat myself.

When time comes to finally get my hands dirty and work on the project, I always do a pull, even knowing I'm the only one with access to the repository, I consider it a good practise.

Right after, I do a composer update, commit the changes and create a new branch.

If everything works as expected, and I achieve my goals, I do a final commit in the new branch, go back to master and merge.

# create a new branch to work on
$ git checkout -b new_feature

# add new files in case I created any
$ git add .

# git changes
$ git commit -am "description of what I did"

# return to master branch
$ git branch master

# merge the branches
$ git merge new_feature

# remove branch
$ git branch -d new_feature 

I only tag my code when a new version is released. When that happens, I keep forgetting to add --tags to the push commands, if not done, tags will be only in local repository.

# adding tag
$ git tag 1.2.2

# push new version to server with tags attached
$ git push --tags server master
14 December, 2012
Tip
Git, VCS

Comments