Git-flow

From OasisSoftTech.com - Knowledge Base/Java/Springframework/Microservices/Cloud-AWS/AI
Jump to: navigation, search

official resource :

https://danielkummer.github.io/git-flow-cheatsheet/

What is git-flow

git-flow are a set of git extensions to provide high-level repository operations for Vincent Driessen's branching model.


This document shows the basic usage and effect of git-flow operations.

Basic tips

  • Git flow provides excellent command line help and output. Read it carefully to see what's happening...
  • The macOS/Windows Client Sourcetree is an excellent git gui and provides git-flow support
  • Git-flow is a merge based solution. It doesn't rebase feature branches.

Installation

You need a working git installation as prerequisite. git

Git flow works on macOS, Linux and Windows

macOS

Homebrew

$ brew install git-flow-avh

Macports

$ port install git-flow-avh

Linux

$ apt-get install git-flow


Windows (Cygwin)

$ wget -q -O - --no-check-certificate https://raw.github.com/petervanderdoes/gitflow-avh/develop/contrib/gitflow-installer.sh install stable | bash

You need wget and util-linux to install git-flow.

Hello World with git-flow

Git flow needs to be initialized in order to customize your project setup.

Create new git repo

$ mkdir git-flow-helloworld
$ cd git-flow-helloworld

$ echo "# git-flow helloworld" >> README.md
$ git init
$ git add README.md
$ git commit -m "git-flow first commit"
$ git remote add origin https://github.com/[git account username]/git-flow-helloworld.git
$ git push -u origin master

Initialize git-flow

Start using git-flow by initializing it inside an existing git repository:

$ git flow init

You'll have to answer a few questions regarding the naming conventions for your branches. It's recommended to use the default values.

$ 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] develop

How to name your supporting branch prefixes?
Feature branches? [feature/] 
Bugfix branches? [bugfix/] 
Release branches? [release/] 
Hotfix branches? [hotfix/] 
Support branches? [support/] 
Version tag prefix? [] 
Hooks and filters directory? [/workspace/git-flow-helloworld/.git/hooks]

Features

  • Develop new features for upcoming releases
  • Typically exist in developers repos only

Start a new feature

Development of new features starting from the 'develop' branch.

Start developing a new feature with

$ git flow feature start MYFEATURE

This action creates a new feature branch based on 'develop' and switches to it

as an example:

$ git flow feature start my-first-gitflow
Switched to a new branch 'feature/my-first-gitflow'

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

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

     git flow feature finish my-first-gitflow

(base) Rasims-MacBook-Pro:git-flow-helloworld $ git branch
  develop
* feature/my-first-gitflow
  master

Finish up a feature

Finish the development of a feature. This action performs the following

  • Merges MYFEATURE into 'develop'
  • Removes the feature branch
  • Switches back to 'develop' branch
$ git flow feature finish MYFEATURE


as an example for our hello-world repo

# make some changes on the feature branch and push
$ git add .
$ git commit -m 'commıt feature branch changes'
$ git push

# git flow finish
$ git flow feature finish my-first-gitflow

Switched to branch 'develop'
Updating 5a49e29..cd4345e
Fast-forward
 README.md | 2 ++
 1 file changed, 2 insertions(+)
To https://github.com/xxxx/git-flow-helloworld.git
 - [deleted]         feature/my-first-gitflow
Deleted branch feature/my-first-gitflow (was cd4345e).

Summary of actions:
- The feature branch 'feature/my-first-gitflow' was merged into 'develop'
- Feature branch 'feature/my-first-gitflow' has been locally deleted; it has been remotely deleted from 'origin'
- You are now on branch 'develop'

we merged our feature branch changes with develop branch, but our job is not finished yet.

Publish a feature

Are you developing a feature in collaboration?

Publish a feature to the remote server so it can be used by other users.

$ git flow feature publish MYFEATURE

as an example:

$ git flow feature publish my-first-gitflow

Getting a published feature

Get a feature published by another user.

$ git flow feature pull origin MYFEATURE

as an example:

$ git flow feature pull origin my-first-gitflow

You can track a feature on origin by using

$ git flow feature track MYFEATURE

as an example:

$ git flow feature track my-first-gitflow

Release

Support preparation of a new production release

Allow for minor bug fixes and preparing meta-data for a release

Start a release

To start a release, use the git flow release command. It creates a release branch created from the 'develop' branch.

$ git flow release start RELEASE [BASE]

You can optionally supply a [BASE] commit sha-1 hash to start the release from. The commit must be on the 'develop' branch.

as an example:

$ git flow release start relase-april2020
Switched to a new branch 'release/relase-april2020'

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

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

     git flow release finish 'relase-april2020'

It's wise to publish the release branch after creating it to allow release commits by other developers. Do it similar to feature publishing with the command:

$ git flow release publish RELEASE

as an example:

$ git flow release publish relase-april2020
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 303 bytes | 303.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: 
remote: Create a pull request for 'release/relase-april2020' on GitHub by visiting:
remote:      https://github.com/xxx/git-flow-helloworld/pull/new/release/relase-april2020
remote: 
To https://github.com/xxx/git-flow-helloworld.git
 * [new branch]      release/relase-april2020 -> release/relase-april2020
Branch 'release/relase-april2020' set up to track remote branch 'release/relase-april2020' from 'origin'.
Already on 'release/relase-april2020'
Your branch is up to date with 'origin/release/relase-april2020'.

Summary of actions:
- The remote branch 'release/relase-april2020' was created or updated
- The local branch 'release/relase-april2020' was configured to track the remote branch
- You are now on branch 'release/relase-april2020'

(You can track a remote release with the

git flow release track RELEASE

command)

Finish up a release

Finishing a release is one of the big steps in git branching. It performs several actions:

  • Merges the release branch back into 'master'
  • Tags the release with its name
  • Back-merges the release into 'develop'
  • Removes the release branch
$ git flow release finish RELEASE

Don't forget to push your tags with

git push origin --tags

as an example:

$ git flow release finish relase-april2020
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
Already on 'master'
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
Switched to branch 'develop'
Already up to date!
Merge made by the 'recursive' strategy.
To https://github.com/xxx/git-flow-helloworld.git
 - [deleted]         release/relase-april2020
Deleted branch release/relase-april2020 (was cd4345e).

Summary of actions:
- Release branch 'release/relase-april2020' has been merged into 'master'
- The release was tagged 'relase-april2020'
- Release tag 'relase-april2020' has been back-merged into 'develop'
- Release branch 'release/relase-april2020' has been locally deleted; it has been remotely deleted from 'origin'
- You are now on branch 'develop'

Hotfixes

  • Hotfixes arise from the necessity to act immediately upon an undesired state of a live production version
  • May be branched off from the corresponding tag on the master branch that marks the production version.

git flow hotfix start

Like the other git flow commands, a hotfix is started with

$ git flow hotfix start VERSION [BASENAME]

The version argument hereby marks the new hotfix release name. Optionally you can specify a basename to start from.

as an example:

$ git flow hotfix start relase-april2020-bugfix

Branches 'master' and 'origin/master' have diverged.
And local branch 'master' is ahead of 'origin/master'.
Switched to a new branch 'hotfix/relase-april2020-bugfix'

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

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

     git flow hotfix finish 'relase-april2020-bugfix'

it creates brand new branch for bug fix from master branch

$ git branch
  develop
* hotfix/relase-april2020-bugfix
  master

make some changes..

Finish a hotfix

By finishing a hotfix it gets merged back into develop and master. Additionally the master merge is tagged with the hotfix version.

$ git flow hotfix finish VERSION

as an example:

$ git flow hotfix finish relase-april2020-bugfix

Branches 'master' and 'origin/master' have diverged.
And local branch 'master' is ahead of 'origin/master'.
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
Deleted branch hotfix/relase-april2020-bugfix (was 6c9f18a).

Summary of actions:
- Hotfix branch 'hotfix/relase-april2020-bugfix' has been merged into 'master'
- The hotfix was tagged 'relase-april2020-bugfix'
- Hotfix tag 'relase-april2020-bugfix' has been back-merged into 'develop'
- Hotfix branch 'hotfix/relase-april2020-bugfix' has been locally deleted
- You are now on branch 'develop'


git-flow-commands.png

to see the git repo for this example, please visit:

https://github.com/rasimsen/git-flow-helloworld

that's all dudes..