Gitflow Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=
* https://danielkummer.github.io/git-flow-cheatsheet/
* https://danielkummer.github.io/git-flow-cheatsheet/
* https://github.com/petervanderdoes/gitflow-avh/wiki/Installation


=Internal=
=Internal=
* [[Git-flow#Subjects|git-flow]]
* [[Gitflow#Subjects|Gitflow]]
 
=Overview=
=Overview=
This page refers to operations with the <code>git-flow</code> extension, if installed. For general git-flow concepts, see [[Gitflow_Concepts#Overview|Gitflow Concepts]].
=Installation=
==Mac==
<syntaxhighlight lang='bash'>
brew install git-flow-avh
</syntaxhighlight>
=Operations=
==git-flow-Enabling a Repository==
If you intend to use the <code>git-flow</code> extension, it is mandatory to "git-flow-enable" the repository with the following command, otherwise the extension commands will complain and will refuse to work. Initialization creates the set of standard branches and branch prefixes required by the git-flow workflow.
<syntaxhighlight lang='bash'>
git flow init
</syntaxhighlight>
The command runs a questionnaire where you should select the default answers, with the exception of the "Version tag prefix", which should be "release":
<font size=-2>
Which branch should be used for bringing forth production releases?
  - develop
Branch name for production releases: [] master
Which branch should be used for integration of the "next release"?
  - develop
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? [] release-
Hooks and filters directory? [/Users/ovidiu/github/some-repository/.git/hooks]
</font>
Note that any newly created branch does not have any corresponding remote branch, so if you want to establish the relationship, apply [[Git_branch#Publish_a_Local_Branch_in_a_Remote_Repository|Publish a Local Branch in a Remote Repository]] procedure.
==Feature==
===Create a Feature Branch===
<syntaxhighlight lang='bash'>
git flow feature start my-feature-branch-1
</syntaxhighlight>
Note that the repository must be "git-flow enabled" for this to work. See [[#git-flow-Enabling_a_Repository|git-flow-enabling a repository]].
The equivalent standard commands:
<syntaxhighlight lang='bash'>
git checkout develop
git checkout -b my-feature-branch-1
</syntaxhighlight>
Note that this command does not push the newly created feature branch into the origin repository. If you wish to do so, follow: {{Internal|Git_branch#Create_the_Remote_Branch_and_its_Local_Remote-Tracking_Branch|Create the Remote Branch and Its Local Remote-Tracking Branch}} and then:  {{Internal|Git_branch#Link_the_Local_Branch_to_its_Tracking_Branch|Link the Local Branch to its Tracking Branch}}
In our case is:
<syntaxhighlight lang='bash'>
git push origin feature/my-feature-branch-1
git branch --set-upstream-to=origin/feature/my-feature-branch-1 feature/my-feature-branch-1
</syntaxhighlight>
===Finish the Feature===
Go to the develop branch and synchronize it with origin:
<syntaxhighlight lang='bash'>
git checkout develop
git pull
</syntaxhighlight>
Then go back to the feature branch and merge develop into it, to preemptively resolve merge conflicts:
<syntaxhighlight lang='bash'>
git checkout feature/my-feature-branch-1
git merge develop
</syntaxhighlight>
From any branch, including the feature branch being worked on (note that you can simply use "my-feature-branch-1", not "feature/my-feature-branch-1", git-flow knows what this is about:
<syntaxhighlight lang='bash'>
git flow feature finish my-feature-branch-1
</syntaxhighlight>
The command will checkout the develop branch and merge my-feature-branch-1 into it, then will delete the feature branch. The equivalent base commands:
<syntaxhighlight lang='bash'>
git checkout develop
git merge my-feature-branch-1
</syntaxhighlight>
==Release==
===Start the Release Process (Making the Release Branch)===
<syntaxhighlight lang='bash'>
git flow release start 0.1.0
</syntaxhighlight>
===Finish a Release===
<syntaxhighlight lang='bash'>
git checkout master
git checkout merge release/0.1.0
git flow release finish ‘0.1.0’
</syntaxhighlight>
==Hotfix==
A hotfix or maintenance brach carries maintenance work for functionality that was released. The results of the maintenance work are used to patch production releases. Hotfix branches are based on [[#Master|master]]. These are the only branches that fork off directly from master. As soon the fix is complete, the hotfix branch should be merged both in [[#Master|master]] and [[#Develop|develop]], or the current [[#Release|release]] branch, if there’s one in progress, and [[#Master|master]] should be tagged with an update release number. Hotfix (maintenance) branches can be thought of as ad-hoc release branches that work directly with master.
===Start a Hotfix===
The repository must be "git-flow enabled" to be able to start a hotfix with git flow. See [[#git-flow-Enabling_a_Repository|git-flow-enabling a repository]].
====Check the Hotfix Branch Root Commit====
Logically, a hotfix branch should be rooted in the master branch commit that was released. Since theoretically it should be no activity on the master after release, that commit should be the [[Git_Concepts#HEAD|HEAD]] of the branch. This can be checked with:
<syntaxhighlight lang='bash'>
git checkout master
git log
</syntaxhighlight>
The HEAD commit should have a "release ..." log entry.
====Start the Hotfix Branch====
To start the hotfix, use the following command ("hotfix/" prefix does NOT need to specified, git-flow will append it):
<syntaxhighlight lang='bash'>
git flow hotfix start my-hotfix-branch-1
</syntaxhighlight>
Example:
<syntaxhighlight lang='bash'>
git flow hotfix start update-creditlimit-fix
</syntaxhighlight>
Note that this command does not push the newly created feature branch into the origin repository. If you wish to do so, follow: {{Internal|Git_branch#Create_the_Remote_Branch_and_its_Local_Remote-Tracking_Branch|Create the Remote Branch and Its Local Remote-Tracking Branch}} and then:  {{Internal|Git_branch#Link_the_Local_Branch_to_its_Tracking_Branch|Link the Local Branch to its Tracking Branch}}
====Increment the Version====
For a Gradle project, the version is conventionally maintained in [[gradle.properties]]. The version should be incremented at this stage. We get a dot version, since we're on a hotfix version, we should increment the patch component and temporarily (until we figure out what is broken) mark it SNAPSHOT
<syntaxhighlight lang='json'>
version=1.3.0
</syntaxhighlight>
should become:
<syntaxhighlight lang='json'>
version=1.3.1-SNAPSHOT
</syntaxhighlight>
===Finish the Hotfix===
====Insure Tests Pass====
Wrap up work, increment all dependencies, if necessary, and make sure all tests pass on the hotfix branch, locally and on the remote build server, if any.
====Set the Dot Release Version====
On the hotfix branch, remove the -SNAPSHOT postfix and set the correct dot release version:
<syntaxhighlight lang='json'>
version=1.3.1-SNAPSHOT
</syntaxhighlight>
should become:
<syntaxhighlight lang='json'>
version=1.3.1
</syntaxhighlight>
then:
<syntaxhighlight lang='bash'>
git add .
git commit -m "release $(grep '^version=' ./gradle.properties | sed -e 's/^.*=//')"
git push
</syntaxhighlight>
====Finish the Hotfix Branch====
The "hotfix/" prefix is not needed, git flow knows to prepend it automatically.
<syntaxhighlight lang='bash'>
git flow hotfix finish my-hotfix-branch-1
</syntaxhighlight>
Example:
<syntaxhighlight lang='bash'>
git flow hotfix finish 'update-creditlimit-fix'
</syntaxhighlight>
During the process, provide a message for the tag that will be generated for the hot fix merge. If the tag is not provided, the "finish" procedure will fail.
The finish procedure will automatically attempt to merge the hotfix branch into both "master" and "develop" and will locally delete the hotfix branch.
If there are conflicts, resolve them on both branches.

Latest revision as of 17:28, 6 March 2024

External

Internal

Overview

This page refers to operations with the git-flow extension, if installed. For general git-flow concepts, see Gitflow Concepts.

Installation

Mac

brew install git-flow-avh

Operations

git-flow-Enabling a Repository

If you intend to use the git-flow extension, it is mandatory to "git-flow-enable" the repository with the following command, otherwise the extension commands will complain and will refuse to work. Initialization creates the set of standard branches and branch prefixes required by the git-flow workflow.

git flow init

The command runs a questionnaire where you should select the default answers, with the exception of the "Version tag prefix", which should be "release":

Which branch should be used for bringing forth production releases?
  - develop
Branch name for production releases: [] master

Which branch should be used for integration of the "next release"?
  - develop
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? [] release-
Hooks and filters directory? [/Users/ovidiu/github/some-repository/.git/hooks]

Note that any newly created branch does not have any corresponding remote branch, so if you want to establish the relationship, apply Publish a Local Branch in a Remote Repository procedure.

Feature

Create a Feature Branch

git flow feature start my-feature-branch-1

Note that the repository must be "git-flow enabled" for this to work. See git-flow-enabling a repository.

The equivalent standard commands:

git checkout develop
git checkout -b my-feature-branch-1

Note that this command does not push the newly created feature branch into the origin repository. If you wish to do so, follow:

Create the Remote Branch and Its Local Remote-Tracking Branch

and then:

Link the Local Branch to its Tracking Branch

In our case is:

git push origin feature/my-feature-branch-1
git branch --set-upstream-to=origin/feature/my-feature-branch-1 feature/my-feature-branch-1

Finish the Feature

Go to the develop branch and synchronize it with origin:

git checkout develop
git pull

Then go back to the feature branch and merge develop into it, to preemptively resolve merge conflicts:

git checkout feature/my-feature-branch-1
git merge develop

From any branch, including the feature branch being worked on (note that you can simply use "my-feature-branch-1", not "feature/my-feature-branch-1", git-flow knows what this is about:

git flow feature finish my-feature-branch-1

The command will checkout the develop branch and merge my-feature-branch-1 into it, then will delete the feature branch. The equivalent base commands:

git checkout develop
git merge my-feature-branch-1

Release

Start the Release Process (Making the Release Branch)

git flow release start 0.1.0

Finish a Release

git checkout master
git checkout merge release/0.1.0
git flow release finish ‘0.1.0’

Hotfix

A hotfix or maintenance brach carries maintenance work for functionality that was released. The results of the maintenance work are used to patch production releases. Hotfix branches are based on master. These are the only branches that fork off directly from master. As soon the fix is complete, the hotfix branch should be merged both in master and develop, or the current release branch, if there’s one in progress, and master should be tagged with an update release number. Hotfix (maintenance) branches can be thought of as ad-hoc release branches that work directly with master.

Start a Hotfix

The repository must be "git-flow enabled" to be able to start a hotfix with git flow. See git-flow-enabling a repository.

Check the Hotfix Branch Root Commit

Logically, a hotfix branch should be rooted in the master branch commit that was released. Since theoretically it should be no activity on the master after release, that commit should be the HEAD of the branch. This can be checked with:

git checkout master
git log

The HEAD commit should have a "release ..." log entry.

Start the Hotfix Branch

To start the hotfix, use the following command ("hotfix/" prefix does NOT need to specified, git-flow will append it):

git flow hotfix start my-hotfix-branch-1

Example:

git flow hotfix start update-creditlimit-fix

Note that this command does not push the newly created feature branch into the origin repository. If you wish to do so, follow:

Create the Remote Branch and Its Local Remote-Tracking Branch

and then:

Link the Local Branch to its Tracking Branch

Increment the Version

For a Gradle project, the version is conventionally maintained in gradle.properties. The version should be incremented at this stage. We get a dot version, since we're on a hotfix version, we should increment the patch component and temporarily (until we figure out what is broken) mark it SNAPSHOT

version=1.3.0

should become:

version=1.3.1-SNAPSHOT

Finish the Hotfix

Insure Tests Pass

Wrap up work, increment all dependencies, if necessary, and make sure all tests pass on the hotfix branch, locally and on the remote build server, if any.

Set the Dot Release Version

On the hotfix branch, remove the -SNAPSHOT postfix and set the correct dot release version:

version=1.3.1-SNAPSHOT

should become:

version=1.3.1

then:

git add .
git commit -m "release $(grep '^version=' ./gradle.properties | sed -e 's/^.*=//')"
git push

Finish the Hotfix Branch

The "hotfix/" prefix is not needed, git flow knows to prepend it automatically.

git flow hotfix finish my-hotfix-branch-1

Example:

git flow hotfix finish 'update-creditlimit-fix'

During the process, provide a message for the tag that will be generated for the hot fix merge. If the tag is not provided, the "finish" procedure will fail.

The finish procedure will automatically attempt to merge the hotfix branch into both "master" and "develop" and will locally delete the hotfix branch.

If there are conflicts, resolve them on both branches.