02.08.22
by Ana Peña Rodriguez
When making changes to a product, it's paramount that all team members work on the correct versions. Using Git, developers can track changes to software code during development. Ana Peña Rodriguez, Scrum Master at Deltatre, explains how to implement a Git workflow for versioning
02.08.22
by Ana Peña Rodriguez
When making changes to a product, it's paramount that all team members work on the correct versions. Using Git, developers can track changes to software code during development. Ana Peña Rodriguez, Scrum Master at Deltatre, explains how to implement a Git workflow for versioning
A Git workflow helps teams develop and deliver isolated features or product increments until they’re completed, documented, tested and approved. Only then are changes incorporated into the main branch and considered deliverable.
Feature isolation makes it easy for multiple developers to work on a particular feature without disturbing the main codebase.
The main branch will never contain incomplete features or broken code. Therefore, anything in the main branch is always deliverable.
When adding new features to an existing product, we suggest the following workflow:
Working on new features
When a bug or error occurs and a hotfix can be done by creating a new hotfix branch. Here’s our process:
Hotfixes
Git branch names help to organize ongoing work to ensure a smooth software delivery. There are two main categories for branch names: permanent and temporary.
Permanent branches
The main branch is for all stable and tested features. It is associated with nightly CI/CD and protected by branch policies. Any changes to main go through PR only.
Tag all releases in the main branch with Git tags.
Temporary branches
When working on a specific feature, use feature/*. Delete after merging on main. Changes from feature branches to the main only go through PR. However, when working on small features, direct commits are allowed.
The qa branch is a write-only branch used for testing new features. No developments are done in this branch.
Used to fix a bug found on main or release/*
Create a release branch when doing a hotfix on an LTS version. The release branch is deleted when a version is no longer maintained. No feature enhancements or chores are allowed.
When creating PR from feature/feature-number-feature-name to main you could have to resolve conflicts.
To do this, you simply merge the latest version of main into your current branch, resolve the conflicts, and push a new commit to origin:
git checkout feature/feature-number-feature-name
git fetch origin && git pull origin main <resolve merge conflicts + commit changes>
For example, let’s say someone developed feature/1234-countdown and made a PR on main, which is still waiting for approval.
If you need some of the files of that branch, you would:
Sometimes we need a range of commits to cherry-pick inside our current branch (imagine a hotfix-branch you want to pull inside your current branch).
We can check the hashes and then type Git cherry-pick ebe6942^..905e279
The first hash in the range is the oldest commit, and the last hash is the newest commit.
This syntax ^ will include the first commit object; otherwise, it won't be included.
Sometimes mistakes can happen. For example, if you accidentally merged qa into your current feature/feature-number-feature-name and pushed it to remote (worst scenario). Or maybe you need to undo some bad commits (e.g. pushed to origin) and delete them from branch history to keep the branch history clean. To fix such mistakes, we recommend the following workflow:
Doing this ASAP will avoid the pull of the polluted branch by other team members.
If you pushed a commit with a wrong/bad message, you could perform these activities to rename your last commit and re-push it to the origin:
git commit --amend -m "New commit message"
git push origin HEAD –force
A Git workflow can help teams work on the correct versions of code without affecting the main codebase before a new feature or increment is ready. We hope that the insight into our workflow and naming conventions helps you implement your own Git workflow.