Lunik's Blog - Properly Handle Git Flow
Lunik's Blog - Properly Handle Git Flow
SysOps IT engineer
Search...
AbuseIPDB Contributor
8,081 IPs Reported
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.
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
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.
1 git add .
2 git commit -m "Prepare development version"
3
1 git branch
2
Result :
1 * develop
2 master
3
Now write the feature and do commit from time to time with :
1 git add .
2 git commit -m "save dev"
3
/!\ 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
First you need to rebase the branch to remove all unecessary commits :
The first commit should always be picked. All other commits can be squashed.
What this command is doing is taking all the commit from the feature branch and
apply them at the end of the developement branch.
First you need to rebase the branch to remove all unecessary commits :
The first commit should always be picked. All other commits can be squashed.
Checkout to the development branch and merge the require feature branch :
First you need to merge the default branch to retreiv all hotfix corrections.
Cleanup
Let's do some cleanup by removing some unused references like feature and hotfix
branches.
< Zero trust deployment with Kubernetes Why pylint rule `W1203` is important >
© 2022 Lunik