What is Git Flow? – An introduction to Git Flow



What is Git Flow? – An introduction to Git Flow

0 0


what-is-git-flow

Presentation for DrupalCamp London 2014: What is Git Flow?

On Github opdavies / what-is-git-flow

What is Git Flow?

An introduction to Git Flow

By Oliver Davies / @opdavies

Drupal for 8 years, Git since for 4 years, Git Flow for a year

Git Flow is...

"A collection of Git extensions to provide high-level repository operations for Vincent Driessen's branching model."

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

* Read quote from slide * Provides a wrapper around standard Git functionality Everything in Git Flow can be done manually

The Branching Model

From

Separates production code from development code Encourages feature driven development Allows for releasing and tagging of code Multiple opportunities for QA and review

Branches

  • master: production code
  • develop: development code
  • feature/*: a specific task or ticket (multiple)
  • release/*: temporary release branch for testing (single)
  • hotfix/*: temporary branch for emergency fixes
master: stable production code, tagged at the end of each release (stable) develop: stores tested and verified development code, awaiting deployment (fairly stable) feature: unstable code relating to a specific task, bug or user story release: hotfix: Used to apply urgent fixes to production code

My rules of Git Flow

Never commit code directly to master Only commit stable code to develop Feature, feature, feature

How can I use it?

You can install and use Git Flow on the command line. There are packages for Ubuntu (apt), Red Hat and CentOS (yum) and OS X (Homebrew). You can also download SourceTree from Atlassian which is cross-platform

Initialise Git Flow

~ $ git flow init

Create your default branches

~ $ git flow init

No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop]

Configure branch prefixes

~ $ git flow init

No branches exist yet. Base branches must be created now.
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? []

Tip: Automatically accept the default branch names

~ $ git flow init -d
# Accepts the default branch names.

Adding -d accepts the default branch names.

Features

$ git flow feature

  • list: lists all features
  • checkout: checks out an existing feature
  • start: starts a new feature
  • finish: finishes a feature
  • publish: pushes a feature into a remote repo
  • pull: pulls a feature from a remote repo

Start a new feature branch

~ $ git flow feature start {name}
~ $ git flow feature start foo

Switched to a new branch 'feature/foo'

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

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

git flow feature finish foo
* Branches from develop

Add and commit changes

~ $ drush dl admin_menu
~ $ git add sites/all/modules/contrib/admin_menu
~ $ git commit -m "Added admin_menu"

Finish a feature

~ $ git flow feature finish {name}
~ $ git flow feature finish foo

Switched to branch 'develop'
Already up-to-date.
Deleted branch feature/foo (was d0cadf1).

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

And repeat...

Releases

$ git flow release

  • list: lists existing releases
  • start: starts a new release
  • finish: finishes a release

Start a new release

~ $ git flow release start {version}
~ $ git flow release start 2014-03-02.0

Switched to a new branch 'release/2014-03-02.0'

Summary of actions:
- A new branch 'release/2014-03-02.0' was created, based on 'develop'
- You are now on branch 'release/2014-03-02.0'

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

     git flow release finish '2014-03-02.0'

Adding -d accepts the default branch names.

Finish a release

~ $ git flow release finish {version}
~ $ git flow release finish 2014-03-02.0

  ...

  Deleted branch release/2014-03-02.0 (was f2aee7d).

  Summary of actions:
  - Latest objects have been fetched from 'origin'
  - Release branch has been merged into 'master'
  - The release was tagged '2014-03-02.0'
  - Release branch has been back-merged into 'develop'
  - Release branch 'release/2014-03-02.0' has been deleted
  • Merges develop into master
  • Enter a tag message
  • Tags the release with the specified tag

Pushing changes remotely

~ $ git push --all
# Push the changes to the remote branches.

~ $ git push --tags
# Push the tags.

Tip: Finish a release in one command

~ $ git flow release finish -pm {message} {version}
# Specify a commit message and automatically push the changes.
~ $ git flow release finish -pm 2014-03-02.0 2014-03-02.0
$ git flow release finish -pm "tag message" {branch}

Hotfixes

$ git flow hotfix

  • list: list all hotfixes
  • start: start a hotfix
  • finish: finish a hotfix
Applies an emergency fix to your production code Branches from master Merged back into master and develop

Resources

Questions?