Skip to content

Instantly share code, notes, and snippets.

@bradlucas
Last active May 2, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradlucas/3f8e58f8a525b8fb382e to your computer and use it in GitHub Desktop.
Save bradlucas/3f8e58f8a525b8fb382e to your computer and use it in GitHub Desktop.
git-flow-pattern.md

"Git is easy to learn and has a tiny footprint with lightning fast performance."

That said you can always learn more.

The more you undertand and use something the more transparent it will be.

If you find yourself struggling with a tool you need to work more with it. Practice.

I highly suggest you practice with personal repos.

Learning Git

Book

Pro Git http://git-scm.com/book

Tutorials

  1. Atlassian Git Tutorial

  2. Learn Version Control with Git

    A step-by-step course for the complete beginner

Articles

  1. Git From the Bottom

Get a good visual Git viewer

  • GitX

  • http://gitx.frim.nl

  • Remember to view 'all branches'

  • Command line

  • $ git log –all –oneline –graph –decorate

Technigues to learn well

Become comfortable with the following:

  • Creating a repo
  • Branching
  • Merging (different types)
  • Deleting branches local and remote
  • Pushing to origin and tracking
  • Creating a local tracking branch

Git Flow (A branching workflow)

  • There are other workflows
  • This isn't necessarilly the best
  • It is popular so you will find it elsewhere
  • You may be familar
  • It's simple enough and if followed everyone will be comfortable in all the repos

Original Article 'A successful Git branching model'

http://nvie.com/posts/a-successful-git-branching-model/

Cheatsheet

Another opinion 'GitFlow considered harmful'

The Pattern (My version)

  • The Git Flow branch model is based on two long running branches.
  • Master and develop exist while features and releases branch off of these and are merged back.
  • Features branch off and back onto develop
  • Releases branch off of develop and are merged back into develop and master
  • Releases are pushed to production
  • Releases at the minimum include a bumped version number and rollbacks are to previous release branches
  • The idea of hotfixes is ignored. Last minute fixes can be handled on the release branch
  • There can be exceptions but you should know what you are doing
  1. Initialize the repo to include master and devlop

    • Clean repo
    • Get rid of old branches including old 'dev' branches
    • Remove old remote branches (this can be done in a script)
    • Merge to master and make sure things are up todate
  2. Initialize Git Flow

    • Create develop
    • Master and develop
  3. Use feature and release branches only

Git Extensions

  • These are scripts that help automate some of the Git Flow tasks.

  • I recommend getting a good understanding of Git and the ideas behind Git Flow first

  • Then these will make sense and the 'magic' then do will be understood.

  • Original

  • git-flow

  • https://github.com/nvie/gitflow

  • Better

  • I wanted to be able to support –no-ff on develop merges

  • git-flow-avh

  • https://github.com/petervanderdoes/gitflow-avh

Local Enhancements

  • I have these to further reduce the amount of details I need to remember
  • The git-finish-release is the most important
  • It has the --no-ff -k to leave the feature branch and merge it without a fast forward
  1. Add to local bashrc

    function git-flow {
      echo "git-start-feature <feature-name>"
      echo "git-finish-feature <feature-name>"
      echo "git-start-release <release-name>"
      echo "git-finish-relase <release-name>"
    }
    
    function git-start-feature {
       echo "todo"
      if [ -z "$1" ]
       then
        echo "Enter feature name"
      else                 
        echo $1
        git flow feature start $1
      fi
    }
    
    function git-finish-feature {
      if [ -z "$1" ]
       then
        echo "Enter feature name"
      else                 
        echo $1
        git flow feature finish --no-ff -k $1
      fi
    }
    
    function git-start-release {
       echo "todo"
      if [ -z "$1" ]
       then
        echo "Enter release name"
      else                 
        echo $1
        git flow release start $1
      fi
    }
    
    function git-finish-release {
      if [ -z "$1" ]
       then
        echo "Enter release name"
      else                 
        echo $1
        git flow release finish -k $1
      fi
    }
    

Summary

  1. Install git-flow-avh

  2. Install Local Functions (above)

  3. Initialize your repos

    • Make sure everything is up to date on master
    • If you have old 'dev' branches get rid of them
    • If you have a 'develop' make sure it is merged to master
    • git flow init
  4. Use features for each development task

    • git flow feature start FEATURE_NAME
    • git flow feature finish FEATURE_NAME
  5. Use release for 'releases'

    • Release are version numbers

    • RELEASE_NUMBER = 0.1.3

    • git flow release start RELEASE_NUMBER

    • bump_version

    • commit

    • git flow release public RELEASE_NUMBER

    • or

    • push origin -u release/RELEASE_NUMBER

    • origin/release/RELEASE_NUMBER is pushed to productions

    • After release is pushed then finish it

    • This will merge back into master and develop

    • git flow release finish RELEASE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment