Git Flow

A successful Git branching model
Why aren’t you using git-flow?

$ brew install git-flow

Project Work Flow

Init Project

$ git init
...
$ git add .
...
$ git commit -m "initial commit"
...
$ git remote add origin git@github.com:CodeSherpas/davebock_www.git
...
$ git push origin master
...
$ git branch
* master
$ git flow init

Which branch should be used for bringing forth production releases?
   - master
Branch name for production release: [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? []
$ git branch
* develop
  master
$ git push origin develop
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:CodeSherpas/davebock_www.git
 * [new branch]      develop -> develop
$ git branch --set-upstream develop origin/develop
Branch develop set up to track remote branch develop from origin.

Feature Branch

$ git flow
usage: git flow <subcommand>

Available subcommands are:
   init      Initialize a new git repo with support for the branching model.
   feature   Manage your feature branches.
   release   Manage your release branches.
   hotfix    Manage your hotfix branches.
   support   Manage your support branches.
   version   Shows version information.

Try 'git flow <subcommand> help' for details.
$ git flow feature
No feature branches exist.

You can start a new feature branch:

    git flow feature start <name> [<base>]

$ git flow feature start pages_controller
Switched to a new branch 'feature/pages_controller'

Summary of actions:
- A new branch 'feature/pages_controller' was created, based on 'develop'
- You are now on branch 'feature/pages_controller'

Now, start committing on your feature. When done, use:

	git flow feature finish pages_controller

$ git branch
  develop
* feature/pages_controller
  master
$ git branch -a
  develop
* feature/pages_controller
  master
  remotes/origin/develop
  remotes/origin/master
$ git flow feature
* pages_controller

[work on feature code]

$ git flow feature publish pages_controller
...

Summary of actions:
- A new remote branch 'feature/pages_controller' was created
- The local branch 'feature/pages_controller' was configured to track the remote branch
- You are now on branch 'feature/pages_controller'

$ git flow feature finish pages_controller
...

Summary of actions:
- The feature branch 'feature/pages_controller' was merged into 'develop'
- Feature branch 'feature/pages_controller' has been removed
- You are now on branch 'develop'

$ git branch
* develop
  master

Release Branch

$ git flow release start initial_deploy
Switched to a new branch 'release/initial_deploy'

Summery of actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

	git flow release finish 'initial_deploy'

$ vi README
$ git add README
$ git commit -m "initial version readme"
...
$ git flow release finish initial_deploy
	[Opens tag window]
...

Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'master'
- The release was tagged 'initial_deploy'
- Release branch has been back-merged into 'develop'
- Release branch 'release/initial_deploy' has been deleted

Hotfix Branch

[creating feature code]
$ git flow feature start blog_sidebar
Switched to a new branch 'feature/blog_sidebar'

Summary of actions:
- A new branch 'feature/blog_sidebar' was created, based on 'develop'
- You are now on branch 'feature/blog_sidebar'

Now, start commiting on your feature. When done, used:

	git flow feature finish blog_sidebar

[wow, found a typo in master...]

$ git flow hotfix start typo_fix
Switched to a new branch 'hotfix/typo_fix'

Summary of actions:
- A new branch 'hotfix/typo_fix' was created, based on 'master'
- You are now on branch 'hotfix/typo_fix'

Follow-up actions:
- Bump the version number now!
- Start committing your hot fixes
- When done, run:

	git flow hotfix finish 'typo_fix'

$ git branch
  develop
  feature/blog_sidebar
* hotfix/typo_fix
  master

[fix typo]

$ git st
# On branch hotfix/typo_fix
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in the working directory)
#
#       modified:   app/views/layouts/application.html.erb
#
$ git add app/views/layouts/application.html.erb
$ git commit -m "fixing the bork typo"
...
$ git flow hotfix finish typo_fix
	[Opens tag window]
...

Summary of actions:
- Latest objects have been fetched from 'origin'
- Hotfix branch has been merged into 'master'
- The hotfix was tagged 'typo_fix'
- Hotfix branch has been back-merged into 'develop'
- Hotfix branch 'hotfix/typo_fix' has been deleted

$ git st
# On branch develop
# Your branch is ahead of 'origin/develop' by 3 commits.
#
nothing to commit (working directory clean)
$ git push
...
$ git branch
* develop
  feature/blog_sidebar
  master
$ git co feature/blog_sidebar
Switched to branch 'feature/blog_sidebar'

Command Summary

$ git init
$ git add .
$ git commit -m "initial commit"
$ git remote add origin git@github.com:CodeSherpas/davebock_www.git
$ git push origin master
$ git branch
* master
$ git flow init
$ git branch
* develop
  master
$ git push origin develop
$ git branch --set-upstream develop origin/develop

$ git flow
$ git flow feature start pages_controller
$ git branch -a
  develop
* feature/pages_controller
  master
  remotes/origin/develop
  remotes/origin/master
$ git flow feature
* pages_controller

$ git flow feature publish pages_controller
$ git flow feature finish pages_controller
$ git branch
* develop
  master

$ git flow release start initial_deploy
$ vi README
$ git add README
$ git commit -m "initial version readme"
$ git flow release finish initial_deploy
	[Opens tag window]

$ git flow feature start blog_sidebar
Switched to a new branch 'feature/blog_sidebar'
$ git flow hotfix start typo_fix
Switched to a new branch 'hotfix/typo_fix'
$ git branch
  develop
  feature/blog_sidebar
* hotfix/typo_fix
  master

$ git st
$ git add app/views/layouts/application.html.erb
$ git commit -m "fixing the bork typo"
$ git flow hotfix finish typo_fix
	[Opens tag window]

$ git st
nothing to commit (working directory clean)
$ git push
$ git branch
* develop
  feature/blog_sidebar
  master
$ git co feature/blog_sidebar
Switched to branch 'feature/blog_sidebar'