Insert GitFlow - Ubuntu ~ Git version control and GitFlow

GitFlow - Ubuntu

To understand about gitflow branches in detail, check Understanding GitFlow

Platform : We're using Ubuntu machine (Linux, Unix).

Overview:




Install gitflow:

$ sudo apt-get install git-flow

Initialize gitflow:

$ git flow init

We need to answer some questions before we proceed to our next steps. 

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? []

Select default values by clicking “Enter”. Above command will initialize existing git repository to use gitflow features. 

After setting up gitflow, we need to run "git branch" command to check which branch we're currently on. We should be on a newly created branch called "develop" but not on master.

$ git branch
* develop
  master

If we’re not on the develop branch, use below command to switch to develop branch.

$ git checkout develop

Let's start working on gitflow branches:

1) Creating Feature Branch:

The purpose of feature branch is that, it should have small unit of work which should last for few hours or days but not weeks or months. With gitflow, we can work on multiple features simultaneously. 

To start a feature, 

$ git flow feature start 111-My-Feature

Switched to a new branch 'feature/111-My-Feature'
Summary of actions:
- A new branch 'feature/111-My-Feature' was created, based on 'develop'
- You are now on branch 'feature/111-My-Feature'
Now, start committing on your feature. 

In the above command, we named newly created feature as "111-My-Feature".  Now as we can see in the message we're on feature branch now. At this point, we can use normal git commands to commit our code. To learn about Git, check Git


Now if we need to collaborate with other team members for the feature we created, we can publish the feature to remote repository so that other team members can use it.

Publish Feature:

·        $ git flow feature publish 111-My-Feature

Counting objects: 6, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 533 bytes | 0 bytes/s, done.
Total 6 (delta 3), reused 0 (delta 0)
remote:
remote: Create pull request for feature/111-My-Feature:
 * [new branch]      feature/111-My-Feature -> feature/111-My-Feature

Already on 'feature/111-My-Feature'
Your branch is up-to-date with 'origin/feature/111-My-Feature'.
Summary of actions:
- A new remote branch 'feature/111-My-Feature' was created
- The local branch 'feature/111-My-Feature' was configured to track the remote branch
    - You are now on branch 'feature/111-My-Feature'

Now, our feature branch is pushed to remote repository and other team members can look into our feature. Whenever we use git flow commands, just use branch name. Do not use feature/branchname, It'll not work.

To get published feature:

$ git pull
$ git checkout feature/111-My-Feature

Make necessary commits and push back into remote repository using “git push origin feature/:111-My-Feature”. 

Once feature is ready we need to merge back into develop branch using “Finish Feature”

Finish Feature:

Once we complete working on our feature, it’s time to merge it back with the main develop branch. We need to use below command to do this.

$ git flow feature finish 111-My-Feature

Switched to branch 'develop'

Updating e2df489..fcc627e
Fast-forward
 data/refdata/rules/Test_feature | 1 +
 1 file changed, 1 insertion(+)

 create mode 100644 data/refdata/rules/Test_feature

 - [deleted]         feature/111-My-Feature
Deleted branch feature/111-My-Feature (was fcc627e).
Summary of actions:
- The feature branch 'feature/111-My-Feature' was merged into 'develop'
- Feature branch 'feature/111-My-Feature' has been locally deleted; it has been remotely deleted from 'origin'
- You are now on branch 'develop'

It's always a best practice to delete a feature once it's merged back into develop. We don't have to manually delete feature. When we run "finish feature" git flow will automatically deletes it from local and also remote repository.

Now that our feature got merged into develop, we can push our develop branch to our remote.

$ git push origin develop

Counting objects: 6, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 533 bytes | 0 bytes/s, done.
Total 6 (delta 3), reused 0 (delta 0)
remote:
remote: Create pull request for develop:
remote:   
 * [new branch]      develop -> develop


2) Creating Release Branch:

Once we merge all our features into develop branch and once develop branch is stable, we are ready for code release. 

Start Release Branch:

$ git flow release start 2016-11-17.0

Switched to a new branch 'release/2016-05-12.0'
Summary of actions:
- A new branch 'release/2016-05-12.0' was created, based on 'develop'
- You are now on branch 'release/2016-05-12.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 '2016-05-12.0'

In the above command, zero after decimal is the increment for the release. Release branch is created off of develop branch. Once we create release branch we need to publish it, so QA can take the code and do some testing.

Publish Release Branch:

git flow release publish 2016-11-17.0

Once testing is completed, we need to finish the release branch which will merge back into develop and master.

Finish Release Branch:

git flow release finish 2016-11-17.0

Switched to branch 'master'
Merge made by the 'recursive' strategy.
 Test_feature | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 Test_feature
Switched to branch 'develop'
Already up-to-date!
Merge made by the 'recursive' strategy.


 - [deleted]         release/2016-05-12.0
Deleted branch release/2016-05-12.0 (was fcc627e).
Summary of actions:
- Release branch 'release/2016-05-12.0' has been merged into 'master'
- The release was tagged '2016-05-12.0'
- Release tag '2016-05-12.0' has been back-merged into 'develop'
- Release branch 'release/2016-05-12.0' has been locally deleted; it has been remotely deleted from 'origin'
- You are now on branch 'develop'

Above command will merge code back into develop and master, create a tag and delete release branch from local and remote repository.

Now, we need to manually push tags into remote repository as git flow will not do it for us.

$ git push --tags

Counting objects: 2, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 395 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
 * [new tag]         2016-05-12.0 -> 2016-05-12.0

3) Creating HotFix Branch:

HotFix branch is similar to release branch, but only difference is that hotfix branch is created off of master branch where as release branch is created off of develop branch.

Start HotFix Branch:

$ git flow hotfix start 2015-06-12.0

Branches 'master' and 'origin/master' have diverged.
And local branch 'master' is ahead of 'origin/master'.
Switched to a new branch 'hotfix/2015-06-12.0'
Summary of actions:
- A new branch 'hotfix/2015-06-12.0' was created, based on 'master'
- You are now on branch 'hotfix/2015-06-12.0'
Follow-up actions:
- Bump the version number now!
- Start committing your hot fixes
- When done, run:
     git flow hotfix finish '2015-06-12.0'

Now we're on HotFix branch, do fixes and commit the code.

Finish HotFix Branch:

$ git flow hotfix finish 2015-06-12.0

Branches 'master' and 'origin/master' have diverged.
And local branch 'master' is ahead of 'origin/master'.
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to branch 'master'
Merge made by the 'recursive' strategy.
 {Test_feature => Test_feature_Hotfix} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename {Test_feature => Test_feature_Hotfix} (100%)
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
 data/refdata/rules/{Test_feature => Test_feature_Hotfix} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 {Test_feature => Test_feature_Hotfix} (100%)
Deleted branch hotfix/2015-06-12.0 (was c76ee78).

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

Above command will merge code back into develop and master and creates master merge tag with hotfix version. Next step is to push our master and tags into remote repository.

$ git push origin master

Counting objects: 6, done.                                                 
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 509 bytes | 0 bytes/s, done.
Total 6 (delta 4), reused 0 (delta 0)
remote:
remote: Create pull request for master.

$ git push --tags

Counting objects: 1, done.
Writing objects: 100% (1/1), 181 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
 * [new tag]         2015-06-12.0 -> 2015-06-12.0




No comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews