Git flow cheatsheet

Created 17th February, 2012 01:09 (UTC), last edited 18th February, 2012 06:04 (UTC)

At Proteus we're doing some experimenting with git for a few new projects. We're making use of git flow, despite an expectation of having problems with it under Windows.

For the examples I'm going to use our profab project on github, but all of our projects work the same way.

Install git flow

Make sure that you have the very latest git flow installed. This will make sure that you are properly tracking the develop branch after you set up a repository.

$ cd /tmp
$ wget —no-check-certificate -q -O - https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | sudo bash
$ git flow version
0.4.2-pre

I do this in /tmp as the sudo execution of the install script leaves a check out of git flow in the current folder with root file permissions.

You really want to install bash completion as well. You also really want to use git cola for managing check ins (apt-get git-cola on Ubuntu).

Check out a git repository

First of all, we need to fetch the data:

$ git clone git@github.com:Proteus-tech/profab.git
Cloning into profab…
remote: Counting objects: 1276, done.
remote: Compressing objects: 100% (478/478), done.
remote: Total 1276 (delta 835), reused 1215 (delta 774)
Receiving objects: 100% (1276/1276), 139.76 KiB | 71 KiB/s, done.
Resolving deltas: 100% (835/835), done.

Then we need to initialize git flow. This has to be done every time a project is cloned.

$ cd profab
$ git flow init -d
Using default branch names.

Which branch should be used for bringing forth production releases?
   - master
Branch name for production releases: [master] 
Branch name for "next release" development: [develop] 

How to name your supporting branch prefixes?
Feature branches? [feature/] 
Release branches? [release/] 
Hotfix branches? [hotfix/] 
Support branches? [support/] 
Version tag prefix? []

This will leave you on the develop branch ready to start working.

$ git branch
* develop
  master

Work on a feature

We track individual tasks by story card, so we'll just follow that convention for now.

$ git flow feature start card-123

This will create the correct branch for you and leave you ready to work on the card.

If during the development of this you want to get changes from the develop branch then you'll need to switch back to it, pull changes and then merge them in to your feature branch.

$ git checkout develop
Switched to branch 'develop'
$ git pull —rebase
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 2), reused 3 (delta 2)
Unpacking objects: 100% (3/3), done.
From github.com:Proteus-tech/profab
9d414f0..4567ef5  develop    -> origin/develop
First, rewinding head to replay your work on top of it…
Fast-forwarded develop to 4567ef5040386ef545d8bfe57bb74b3f6cdb8ad3.
$ git checkout feature/card-123
Switched to branch 'feature/card-123'
$ git rebase develop
First, rewinding head to replay your work on top of it…
Fast-forwarded feature/card-123 to develop.

The use of rebase is important here as it makes sure that any changes you have made are put after the changes you get from the origin. This makes merge conflicts far easier to deal with and also makes the history easier to understand as commits don't get interleaved.

In any case, when you've finished a feature you need to get your changes back in to develop.

$ git flow feature finish card-123
Switched to branch 'develop'
Already up-to-date.
Deleted branch feature/card-123 (was 4567ef5).

Summary of actions:
- The feature branch 'feature/card-123' was merged into 'develop'
- Feature branch 'feature/card-123' has been removed
- You are now on branch 'develop'
$ git pull —rebase
Current branch develop is up to date.
$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 429 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
To git@github.com:Proteus-tech/profab.git
9d414f0..4567ef5  develop -> develop

Setting up a new repository for a client project

This is pretty simple.

$ mkdir -p client/project.git
$ cd !$
cd client/project.git
$ git init —bare
Initialized empty Git repository in /home/git/client/project.git/

Categories: