059 Git Flow

14 Jun 2014

Git Flow is a git branch model. In this episode, we will create a git repository and then add the git flow branching model to it. We will also explore how to start a feature, hotfix of a release with the command line or SourceTree App. Finally, we will find out how to display the git commits in a graph.

Download video: mp4

Sample code: Github

Version: 1.7.0 (AVH Edition)

Similar episodes: 004 Git, 015 GitHub

##Background on Git Flow

  1. A successful Git branching model
  2. Original github repo and updated fork
  3. Git Flow AVH

##Things to learn with Git Flow

###1. install

  1. install git-flow avh edition. E.g. for Mac OS X 1.install with brew

    brew install git-flow-avh

  2. try out the command in the terminal

    git flow version git flow

###2. start a normal git repo

  1. create a file cal.md to include notes on the Cosmic Calendar
  2. initialise a git repo as we normally do

    git init git add cal.md git commit -m "initial commit"

  3. pretty git log graphs

  4. edit cal.md

    ``` ##Big Bang

    • 1 Jan: Big bang
    • 15 Mar: Milky Way Galaxy formed
    • 31 Aug: Sun formed
    • 16 Sep: Oldest rocks on Earth ```
  5. commit it

    git status git add cal.md git commit -m "Big bang cal added"

  6. view the commits as git log command and with gitx

###3. integrate git flow

  1. integrate git flow in an existing repo

    git flow init

  2. answer the questions accordingly

    ``` 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? [] Hooks and filters directory? [.git/hooks] ```

  3. notice that the branch is automatically in develop

    ``` $ git branch

    • develop master ```

###4. new feature

  1. start a new feature on the feature-name branch

    git flow feature start earth-cal

  2. some earth calendar is added to cal.md

    - 21 Sep: prokaryotes - 12 Oct: photosynthesis - 29 Oct: Oxygenation of atmosphere - 9 Nov: complex cells (eukaryotes)

  3. commit it

    git add . git commit -m "added sep-nov earth cal" git branch git log

  4. another feature branch

    $ git flow feature start human-cal $ git branch

  5. some edits

    ``` ##Human

    • 30 Dec: Primates
    • 31 Dec, 06:05: Apes
    • 31 Dec, 14:24: hominids
    • 31 Dec, 22:24: primitive humans and stone tools
    • 31 Dec, 23:44: Domestication of fire ```
  6. commit it

    git add cal.md git commit -m "some human events added"

  7. go back to another feature branch feature/earth-cal

    git checkout feature/earth-cal

  8. complete the calendar for earth

    ... - 18 Dec: fish and proto-amphibians - 20 Dec: land plants - 21 Dec: insects and seeds - 22 Dec: amphibians - 23 Dec: reptiles - 26 Dec: mammals - 27 Dec: birds - 28 Dec: flowers - 30 Dec, 06:24: Cretaceous–Paleogene extinction event

  9. commit it

    git add cal.md git commit -m "earth cal completed" git status git branch git log

###5. complete feature

  1. ensure you are in branch feature/earth-cal
  2. complete the feature

    git flow feature finish earth-cal git branch git log - merged back to develop branch - delete git flow feature finish earth-cal - switch back to develop branch

  3. view in SourceTree App > File > Open

###6. publish a feature

  1. create a new repo in github and add remote repository

    $ git remote add origin git@github.com:username/project-name.git $ git push -u origin master

  2. publish a feature

    git flow feature publish human-cal

  3. go to github and view the new branch

###7. make a release

  1. create a release branch from the develop branch with semantic versioning

    git checkout develop git flow release start 0.1.0 git branch

  2. publish the release and view on github

    git flow release publish 0.1.0

  3. finish up a release with tag and commit messages

    git flow release finish 0.1.0 git push --tags

###8. do a hotfix

  1. start a hotfix

    git flow hotfix start heading

  2. commit changes

    git add cal.md git commit -m "amended heading to h3"

  3. finish a hotfix

    git flow hotfix finish heading

  4. push all tags and view on github

    git push --tags

###9. using source tree app

  1. in Sourcetree App, right click feature/human-cal and Checkout feature/human-cal
  2. add the remaining calendar

    - 31 Dec, 23:52 Anatomically modern humans - 31 Dec, 23:55 Beginning of most recent glacial period - 31 Dec, 23:58 sculpture and painting - 31 Dec, 23:59:32 Agriculture - 31 Dec, 23:59:59 modern science and technology, American Revolution, French revolution, World War I, World War II, Apollo Moon landing

  3. click commit in the header with commit message “complete human cal”
  4. click Git Flow > Finish Current
  5. merge conflict manually in the text editor
  6. final commit from the header button
  7. Git flow button has more actions available in the command line as well

###10. git flow cli completion

  1. install for zsh
  2. try it out in the command line!

    $ git flow feature -v -- Verbose (more) output checkout -- Checkout local feature branch. diff -- Show all changes. finish -- Finish a feature branch. list -- List all your feature branches. (Alias to `git flow feature`) publish -- Publish feature branch to remote. pull -- Pull changes from remote. rebase -- Rebase from integration branch. start -- Start a new feature branch. track -- Checkout remote feature branch.

##More Resources on Git Flow

  1. Git Flow cheatsheet
  2. Git workflows
  3. Pros and Cons of using Git Flow
  4. git flow with sourcetree app
  5. Git Flow eBook

##Credits 1. Cosmic Calendar

##Build Link of this episode

DevDocs - multiple documentations in a fast, organised and searchable interface.