Git-Flow
for Daily Use
Kevin Basarab
Twitter: @kBasarab
IRC: @kBasarab
Prereqs
● Git 101
● A multiple environment setup (Dev-Stage-Prod)
● Comfortable on the CLI
Benefits
● Parallel Development
● Collaboration
● Release Staging
● Support for Emergency fixes
Source: http://datasift.github.com/gitflow/IntroducingGitFlow.html
What is Git-Flow
● At the core Git-flow is a branching and merging strategy
● GIT branches are cheap, merges are easy
● Other systems: Each branch is a complete replication of codebase
Branching 101
> git branch -a;
develop
new_branch
*develop
master
remotes/origin/master
remotes/origin/develop
> git checkout -b new_branch
Switched to a new branch 'new_branch'
> git branch
develop
...
*new_branch
> git branch test_2
Merging 101
> git checkout develop;
Switched to branch 'develop'
> git merge new_branch
● Master Branch
○ The production site codebase
● Develop Branch
○ All code ready for production on a staging environment
● Feature
○ Active code development. Usually related to one ticket.
● Release
○ Integration branch to test develop merging into master
● Hotfix
○ Emergency fix to the production site
Terminology
Visualize Git-Flow
Source: http://nvie.com/posts/a-successful-git-branching-model/
Visualize Git-Flow
Source: http://nvie.com/posts/a-successful-git-branching-model/
Visualize Git-Flow
Source: http://nvie.com/posts/a-successful-git-branching-model/
Visualize Git-Flow
Source: http://nvie.com/posts/a-successful-git-branching-model/
Source: http://bit.ly/10iUTKK
Scenario
● Start using git-flow on a basic git repo
● Roll code based on a ticket
● Have a peer code review or help build functionality.
● Release this to production
● We had a misspelling, fix on production
Setup Git-Flow
● Install git-flow locally.
○ https://github.com/nvie/gitflow/wiki/Mac-OS-X
○ https://github.com/nvie/gitflow/wiki/Linux
○ https://github.com/nvie/gitflow/wiki/Windows
> git status
# On branch master
nothing to commit (working directory clean)
> git-flow init
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? []
> git checkout develop
Create feature
> git branch
* develop
master
> git-flow feature start 1234-78900-Add-Feature
Switched to a new branch 'feature/1234-78900-Add-Feature'
Summary of actions:
- A new branch 'feature/1234-78900-Add-Feature' was created, based on
'develop'
- You are now on branch 'feature/1234-78900-Add-Feature'
Now, start committing on your feature. When done, use:
git flow feature finish 1234-78900-Add-Feature
> git-flow feature publish 1234-78900-Add-Feature
Total 0 (delta 0), reused 0 (delta 0)
remote: bb/acl: kbasarab is allowed. accepted payload.
To test.git
* [new branch] feature/1234-78900-Add-Feature -> feature/1234-
78900-Add-Feature
Already on 'feature/1234-78900-Add-Feature'
Summary of actions:
- A new remote branch 'feature/1234-78900-Add-Feature' was created
- The local branch 'feature/1234-78900-Add-Feature' was configured to
track the remote branch
- You are now on branch 'feature/1234-78900-Add-Feature'
Publish feature
# Another user on another computer:
> git fetch
> git checkout feature/1234-78900-Add-Feature
...
> git fetch; git rebase origin/feature/1234-78900-Add-Feature
...
> git push origin feature/1234-78900-Add-Feature
> git-flow feature finish 1234-78900-Add-Feature
Switched to branch 'develop'
Already up-to-date.
Deleted branch feature/1234-78900-Add-Feature (was f135b69).
Summary of actions:
- The feature branch 'feature/1234-78900-Add-Feature' was merged into
'develop'
- Feature branch 'feature/1234-78900-Add-Feature' has been removed
- You are now on branch 'develop'
Finish feature
> git push origin develop
Total 0 (delta 0), reused 0 (delta 0)
remote: bb/acl: kbasarab is allowed. accepted payload.
To test.git
f22f2d0..f135b69 develop -> develop
> git push origin :feature/1234-78900-Add-Feature
remote: bb/acl: kbasarab is allowed. accepted payload.
To test.git
- [deleted] feature/1234-78900-Add-Feature
> git-flow release start 2013-03-14.0
Switched to a new branch 'release/2013-03-14.0'
Summary of actions:
- A new branch 'release/2013-03-14.0' was created, based on 'develop'
- You are now on branch 'release/2013-03-14.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 '2013-03-14.0'
Create release
> git push origin release/2013-03-14.0
Total 0 (delta 0), reused 0 (delta 0)
remote: bb/acl: kbasarab is allowed. accepted payload.
To test.git
* [new branch] release/2013-03-14.0 -> release/2013-03-14.0
> git-flow release finish 2013-03-14.0
Switched to branch 'master'
Merge made by the 'recursive' strategy.
example.txt | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
Deleted branch release/2013-03-14.0 (was f135b69).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'master'
- The release was tagged '2013-03-14.0'
- Release branch has been back-merged into 'develop'
- Release branch 'release/2013-03-14.0' has been deleted
> git push origin :release/2013-03-14.0
remote: bb/acl: kbasarab is allowed. accepted payload.
To test.git
- [deleted] release/2013-03-14.0
Finish release
> git push --tags
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 352 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: bb/acl: kbasarab is allowed. accepted payload.
To test.git
* [new tag] 2013-03-14.0 -> 2013-03-14.0
Finish release
> git-flow hotfix start 2013-03-17.0
Switched to a new branch 'hotfix/2013-03-17.0'
Summary of actions:
- A new branch 'hotfix/2013-03-17.0' was created, based on 'master'
- You are now on branch 'hotfix/2013-03-17.0'
Follow-up actions:
- Bump the version number now!
- Start committing your hot fixes
- When done, run:
git flow hotfix finish '2013-03-17.0'
> ... Commits
> git-flow hotfix finish 2013-03-17.0
> git push origin master
> git push --tags
Hotfix
● http://www.mediacurrent.com/blog/webinar-git-intro
● http://nvie.com/posts/a-successful-git-branching-model/
● http://datasift.github.com/gitflow/IntroducingGitFlow.html
Resources
Thank You!
Questions
Twitter: @kBasarab
IRC: @kBasarab

Git flow for daily use

  • 1.
    Git-Flow for Daily Use KevinBasarab Twitter: @kBasarab IRC: @kBasarab
  • 2.
    Prereqs ● Git 101 ●A multiple environment setup (Dev-Stage-Prod) ● Comfortable on the CLI
  • 3.
    Benefits ● Parallel Development ●Collaboration ● Release Staging ● Support for Emergency fixes Source: http://datasift.github.com/gitflow/IntroducingGitFlow.html
  • 4.
    What is Git-Flow ●At the core Git-flow is a branching and merging strategy ● GIT branches are cheap, merges are easy ● Other systems: Each branch is a complete replication of codebase
  • 5.
    Branching 101 > gitbranch -a; develop new_branch *develop master remotes/origin/master remotes/origin/develop > git checkout -b new_branch Switched to a new branch 'new_branch' > git branch develop ... *new_branch > git branch test_2
  • 6.
    Merging 101 > gitcheckout develop; Switched to branch 'develop' > git merge new_branch
  • 7.
    ● Master Branch ○The production site codebase ● Develop Branch ○ All code ready for production on a staging environment ● Feature ○ Active code development. Usually related to one ticket. ● Release ○ Integration branch to test develop merging into master ● Hotfix ○ Emergency fix to the production site Terminology
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
    Scenario ● Start usinggit-flow on a basic git repo ● Roll code based on a ticket ● Have a peer code review or help build functionality. ● Release this to production ● We had a misspelling, fix on production
  • 14.
    Setup Git-Flow ● Installgit-flow locally. ○ https://github.com/nvie/gitflow/wiki/Mac-OS-X ○ https://github.com/nvie/gitflow/wiki/Linux ○ https://github.com/nvie/gitflow/wiki/Windows > git status # On branch master nothing to commit (working directory clean) > git-flow init 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? []
  • 15.
    > git checkoutdevelop Create feature > git branch * develop master > git-flow feature start 1234-78900-Add-Feature Switched to a new branch 'feature/1234-78900-Add-Feature' Summary of actions: - A new branch 'feature/1234-78900-Add-Feature' was created, based on 'develop' - You are now on branch 'feature/1234-78900-Add-Feature' Now, start committing on your feature. When done, use: git flow feature finish 1234-78900-Add-Feature
  • 16.
    > git-flow featurepublish 1234-78900-Add-Feature Total 0 (delta 0), reused 0 (delta 0) remote: bb/acl: kbasarab is allowed. accepted payload. To test.git * [new branch] feature/1234-78900-Add-Feature -> feature/1234- 78900-Add-Feature Already on 'feature/1234-78900-Add-Feature' Summary of actions: - A new remote branch 'feature/1234-78900-Add-Feature' was created - The local branch 'feature/1234-78900-Add-Feature' was configured to track the remote branch - You are now on branch 'feature/1234-78900-Add-Feature' Publish feature # Another user on another computer: > git fetch > git checkout feature/1234-78900-Add-Feature ... > git fetch; git rebase origin/feature/1234-78900-Add-Feature ... > git push origin feature/1234-78900-Add-Feature
  • 17.
    > git-flow featurefinish 1234-78900-Add-Feature Switched to branch 'develop' Already up-to-date. Deleted branch feature/1234-78900-Add-Feature (was f135b69). Summary of actions: - The feature branch 'feature/1234-78900-Add-Feature' was merged into 'develop' - Feature branch 'feature/1234-78900-Add-Feature' has been removed - You are now on branch 'develop' Finish feature > git push origin develop Total 0 (delta 0), reused 0 (delta 0) remote: bb/acl: kbasarab is allowed. accepted payload. To test.git f22f2d0..f135b69 develop -> develop > git push origin :feature/1234-78900-Add-Feature remote: bb/acl: kbasarab is allowed. accepted payload. To test.git - [deleted] feature/1234-78900-Add-Feature
  • 18.
    > git-flow releasestart 2013-03-14.0 Switched to a new branch 'release/2013-03-14.0' Summary of actions: - A new branch 'release/2013-03-14.0' was created, based on 'develop' - You are now on branch 'release/2013-03-14.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 '2013-03-14.0' Create release > git push origin release/2013-03-14.0 Total 0 (delta 0), reused 0 (delta 0) remote: bb/acl: kbasarab is allowed. accepted payload. To test.git * [new branch] release/2013-03-14.0 -> release/2013-03-14.0
  • 19.
    > git-flow releasefinish 2013-03-14.0 Switched to branch 'master' Merge made by the 'recursive' strategy. example.txt | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) Deleted branch release/2013-03-14.0 (was f135b69). Summary of actions: - Latest objects have been fetched from 'origin' - Release branch has been merged into 'master' - The release was tagged '2013-03-14.0' - Release branch has been back-merged into 'develop' - Release branch 'release/2013-03-14.0' has been deleted > git push origin :release/2013-03-14.0 remote: bb/acl: kbasarab is allowed. accepted payload. To test.git - [deleted] release/2013-03-14.0 Finish release
  • 20.
    > git push--tags Counting objects: 2, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 352 bytes, done. Total 2 (delta 0), reused 0 (delta 0) remote: bb/acl: kbasarab is allowed. accepted payload. To test.git * [new tag] 2013-03-14.0 -> 2013-03-14.0 Finish release
  • 21.
    > git-flow hotfixstart 2013-03-17.0 Switched to a new branch 'hotfix/2013-03-17.0' Summary of actions: - A new branch 'hotfix/2013-03-17.0' was created, based on 'master' - You are now on branch 'hotfix/2013-03-17.0' Follow-up actions: - Bump the version number now! - Start committing your hot fixes - When done, run: git flow hotfix finish '2013-03-17.0' > ... Commits > git-flow hotfix finish 2013-03-17.0 > git push origin master > git push --tags Hotfix
  • 22.
  • 23.