0% found this document useful (0 votes)
152 views10 pages

Lunik's Blog - Properly Handle Git Flow

This document provides guidelines for properly managing Git workflow and flow, including: 1) Using a development branch to merge all new features and changes before merging to the main/master branch. 2) Creating feature branches for new features and hotfix branches only for critical issues. 3) Merging completed features/fixes into the development branch after rebasing and squashing commits. 4) Releasing work by merging the development branch into main/master and cleaning up old branches.

Uploaded by

Prashantcool1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views10 pages

Lunik's Blog - Properly Handle Git Flow

This document provides guidelines for properly managing Git workflow and flow, including: 1) Using a development branch to merge all new features and changes before merging to the main/master branch. 2) Creating feature branches for new features and hotfix branches only for critical issues. 3) Merging completed features/fixes into the development branch after rebasing and squashing commits. 4) Releasing work by merging the development branch into main/master and cleaning up old branches.

Uploaded by

Prashantcool1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lunik's Blog

SysOps IT engineer

Search...

website wall of fame

AbuseIPDB Contributor
8,081 IPs Reported

HOME ARCHIVES CATEGORIES TAGS ATOM

Properly handle Git flow en fr

Posted on Sun 11 September 2022 in articles

Table of Contents

Context
Basics
Full example of a repository lifecycle
Initializing a repository
Initializing the development branch
Add the first feature
Work on a required feature
Merging the required feature
Continuing the work on the first feature
Merging the first feature
Hotfix critical issue
Releasing your work
Cleanup
Notes
Context
Any developper use or will use Git at a point in is career. Most of the time they will
have to work with other people on the same Git repository. To avoid it to be branch
and commit battlefield here is a simple guide on how to contribute properly on a Git
repository.

Basics
First of all, the Git repository should have a default branch often called master or
main (it may be anything else as long as everyone agree on the name).

Secondly, a second branch used for development purpose. This one will follow the
default branch pretty closely. It will be a receptacle for any new development. This
branch is the only one allowed to be merged on the default branch.

Finally, all other branch fall into the last category. They are features, bugs fix and other.

Note : Only HotFix branches are allowed to bypass the development branch.

Here is an example of a simple Git repository

Full example of a repository lifecycle


Initializing a repository
The first thing to do when creating a new repository, is to initialize the base structure.

Create the Git repository :

1 mkdir -p myrepository
2
3 cd myrepository
4
5 git init
6

You may want to create your first files. Like the README.md/.gitignore and some
package file like package.json or pom.xml.

Then create the initial commit of the repository with those files :

1 git add .
2 git commit -m "Initial commit"
3 git tag v0.0.0
4

Finally create the development branch :

1 git branch develop


2

The repository should looks like :

Initializing the development branch


Now that you have ou base structure on the Git repository, it's time initialize the
development branch.

First checkout to the development branch :

1 git checkout develop


2

Sometimes you may want to add an initial commit on the development branch with
the modification of the current version in your package file package.json, pom.xml
or other.

Edit thoses files then create a commit :

1 git add .
2 git commit -m "Prepare development version"
3

The repository should looks like :

Add the first feature


Now let's create the first feature in our application.

Verify that your are on the development branch :

1 git branch
2

Result :

1 * develop
2 master
3

If not checkout on the development branch.

Then checkout to a feature branch :

1 git checkout -b feature/my-first-feature


2

Now write the feature and do commit from time to time with :

1 git add .
2 git commit -m "save dev"
3

The repository should looks like :


Work on a required feature
You where working on the first feature but you realize that you needed another one to
continue.

/!\ Make sure that you don't have any unstaged changes before switching branches

Reproduce the same commands as for the first feature : - Checkout to the
development branch - Then checkout to a feature branch - Write your code and create
commits

1 git checkout develop


2 git checkout -b feature/my-required-feature
3

The repository should looks like :

Merging the required feature


Now that you have finished your work on the required feature comes the time to
merge the code to the development branch.

First you need to rebase the branch to remove all unecessary commits :

1 git rebase -i develop


2

The first commit should always be picked. All other commits can be squashed.

1 pick fa71872 save dev


2 squash 5d9a97a save dev
3

The repository should looks like :


Checkout to the development branch and merge the require feature branch :

1 git checkout develop


2 git merge --no-ff feature/my-required-feature
3

The repository should looks like :

Continuing the work on the first feature


Now that you have finished the required feature, you want to rebase your current work
on the first feature to retrieve the content of the required feature.

Checkout to the feature branch


Rebase it on the developement branch

1 git checkout feature/my-first-feature


2 git rebase develop
3

What this command is doing is taking all the commit from the feature branch and
apply them at the end of the developement branch.

The repository should looks like :


Merging the first feature
Now that you have finished your work on the first feature comes the time to merge the
code to the development branch.

First you need to rebase the branch to remove all unecessary commits :

1 git rebase -i develop


2

The first commit should always be picked. All other commits can be squashed.

1 pick 717051b save dev


2 squash 7d39273 save dev
3 squash 7b700f1 save dev
4

The repository should looks like :

Checkout to the development branch and merge the require feature branch :

1 git checkout develop


2 git merge --no-ff feature/my-first-feature
3

The repository should looks like :


Hotfix critical issue
A critical issue have been discovered on the production application an you need to
quickly produce a patch. You don't have the time to go through all the release process.

Checkout from the default branch


Create a new hotfix branch and checkout to it
Make the correction
Merge into the default branch
Tag your new release

The repository should looks like :

Releasing your work


It's now time to release all that hard work.

First you need to merge the default branch to retreiv all hotfix corrections.

1 git checkout develop


2 git merge --no-ff master
3

The repository should looks like :


And finaly, merge your development on the default branch.

1 git checkout master


2 git merge --no-ff develop
3

The repository should looks like :

Cleanup
Let's do some cleanup by removing some unused references like feature and hotfix
branches.

1 git branch -D feature/my-first-feature


2 git branch -D feature/my-required-feature
3 git branch -D hotfix/correct-critical-issue
4

The repository should looks like :


Notes
All Git graph have been generated with Bit-Booster app

git gitflow merge request pull request feature

< Zero trust deployment with Kubernetes Why pylint rule `W1203` is important >

© 2022 Lunik

You might also like