Git Workflow Standards and Best Practices Every Developer Must Know
Last updated
Last updated
Git is widely recognized as a powerful version control tool that every developer should master. While many are familiar with its basic functionalities, how does a team effectively use Git to manage source code collaboratively? In this post, I’ll share the standard Git workflow and best practices for managing source code in a team environment.
In Git, branches are used to create separate environments for development. Here, we’ll focus on two primary branches: main and develop. Some companies may use alternative names like master or dev, but their purposes remain the same.
Main Branch: This is the primary branch that represents the production-ready code. It contains the most stable and tested version of the application. After the development team completes a feature, the code is merged into this branch. The main branch is used for deploying the final product to customers.
Develop Branch: This is the development branch where most of the coding happens. Developers merge their completed features into this branch. After a certain period, the team leader reviews the code and decides whether to merge it into the main branch for a new product release. Some companies follow a Scrum process, where the team reviews and tests the product before merging it into main.
To better understand how Git manages source code for both teams and individuals, let’s break down the workflow into clear steps:
Step 1: Start a New Feature
Create an issue for the feature you’re working on.
From the develop branch, create a new branch named after the feature (e.g., feature/login-page
).
Developers will work on this new branch and commit their changes using the following format:
#<issue-number> - <commit-message>
(e.g., #123 - Add login functionality
).
Step 2: Work on the Feature
All commits related to the feature should be made to the feature branch.
Ensure that the code is clean, well-documented, and follows the team’s coding standards.
Step 3: Merge Feature into Develop
Once the feature is complete, merge the feature branch into the develop branch.
The team will then review and test all features merged into develop. Pro Tip: Regular communication within the team can help minimize conflicts during merges.
Step 4: Merge Develop into Main
After testing and approval, merge the develop branch into the main branch.
Create a release and add tags in Git to mark the version. This step ensures that the main branch always reflects the latest stable release.
Step 5: Hotfixes for Bugs
If a bug is found after a release, create a hotfix issue.
Checkout a new branch from the main branch (e.g., hotfix/login-bug
).
Fix the bug, merge it back into main, and create a new release to deliver the fix to customers promptly.
To ensure smooth and disciplined teamwork, here are some essential rules to follow:
Frequent Commits: Commit code regularly to avoid losing work and to make tracking changes easier.
Daily Pulls: Always pull the latest changes from the develop branch at the start of your workday to stay updated.
Main and Develop Branch Alignment: Ensure the main branch is always up-to-date with the develop branch after a release. The main branch should never be ahead of develop.
Clear Commit Messages:
Use a consistent commit message format, such as:
feat/add function ABC
(for new features) or fix/resolve login bug
(for bug fixes).
Team Communication: Regular interaction within the team is crucial to avoid conflicts and ensure high productivity.
The above workflow represents the standard Git process for managing source code in a team. By following these best practices, you can ensure efficient collaboration, minimize conflicts, and deliver high-quality software.