println it

Software blog about tools, builds and making it all work

My Git Workflow

When you work with Subversion you don’t talk much about workflow because there’s only one available 99% of time:

..
svn update
svn status
svn commit
..

I have an "ss" alias to "svn update && svn status" combination which I run very frequently for any project I come across. I believe most Subversion issues are caused by not running those two simple commands in time.

But it is different in Git. Since network topology, branching methodology and behavioral patterns may vary for each team (and that’s what makes Git git!) there’s a place to talk about Git workflow.

In my projects I don’t use “feature branches” much but I always work with two branches: "master" and "dev". The development only happens in "dev" which is rebased and merged with "master" when I feel it makes sense. Nightly builds build them all but only "master" artifacts are deployed to Artifactory as snapshots.

For 2 projects I have 4 branches and three different environments where I could update any of them: home, office or netbook. As I felt there’s too much time spent on bringing each project in sync with GitHub, I put together a number of scripts to update and push changes for each of them easily.

"update.bat":

@echo off

call git checkout dev
call git status
call git pull origin dev
call git checkout master
call git status
call git pull origin master
call git checkout dev

"merge.bat":

@echo off

call git checkout dev
call git status
call git rebase master
call git checkout master
call git status
call git merge dev
call git push origin
call git checkout dev

So when I approach a project I just type "update" to get it started or "merge" to wrap it up. There’s also a "merge-all.bat" script to call it a day:

@echo off

cls
e:

echo "=========> gcommons"
cd \projects\gcommons
call update
call merge

echo "=========> maven-plugins"
cd \projects\maven-plugins
call update
call merge

echo "=========> scripts"
cd \projects\scripts
call git status
call git pull origin master
call git push origin master

echo "=========> maven-plugins-test"
cd \projects\maven-plugins-test
call git status
call git pull origin master
call git push origin master

If everything is clean and no updates are left behind, I expect it to display:

"=========> gcommons"
Already on 'dev'
# On branch dev
nothing to commit (working directory clean)
From github.com:evgeny-goldin/gcommons
 * branch            dev        -> FETCH_HEAD
Already up-to-date.
Switched to branch 'master'
# On branch master
nothing to commit (working directory clean)
From github.com:evgeny-goldin/gcommons
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Switched to branch 'dev'
Already on 'dev'
# On branch dev
nothing to commit (working directory clean)
Current branch dev is up to date.
Switched to branch 'master'
# On branch master
nothing to commit (working directory clean)
Already up-to-date.
Everything up-to-date
Switched to branch 'dev'
"=========> maven-plugins"
Switched to branch 'dev'
# On branch dev
nothing to commit (working directory clean)
From github.com:evgeny-goldin/maven-plugins
 * branch            dev        -> FETCH_HEAD
Already up-to-date.
Switched to branch 'master'
# On branch master
nothing to commit (working directory clean)
From github.com:evgeny-goldin/maven-plugins
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Switched to branch 'dev'
Already on 'dev'
# On branch dev
nothing to commit (working directory clean)
Current branch dev is up to date.
Switched to branch 'master'
# On branch master
nothing to commit (working directory clean)
Already up-to-date.
Everything up-to-date
Switched to branch 'dev'
"=========> scripts"
# On branch master
nothing to commit (working directory clean)
From github.com:evgeny-goldin/scripts
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Everything up-to-date
"=========> maven-plugins-test"
# On branch master
nothing to commit (working directory clean)
From github.com:evgeny-goldin/maven-plugins-test
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Everything up-to-date

,

One Response to “My Git Workflow”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>