Git Workflows

Git workflows provide a set of rules and guidelines for using branches effectively in a collaborative environment. Here are two popular Git workflows


GitFlow is a branching model designed for projects that follow a strict release cycle. It provides a clear separation of features, releases, and hot-fixes, making it suitable for larger projects with longer development cycles.

Workflow Steps in GitFlow

  • Create a new feature branch from the "develop" branch.

  • Develop the feature and commit changes.

  • Merge the feature branch back into the "develop" branch.

  • Create a release branch from the "develop" branch.

  • Perform necessary bug fixes and adjustments in the release branch.

  • Merge the release branch into both "develop" and "master" branches.

  • Tag the merged commit on the "master" branch with a version number.

Github Flow

GitHub Flow is a lightweight and flexible workflow that encourages continuous delivery and frequent deployments. It is suitable for smaller teams or projects that require a simpler branching model.

Workflow Steps in Github Flow

  1. Create a new branch from the main branch (e.g., "master" or "main").

  2. Develop the feature or fix in the branch.

  3. Commit changes and push the branch to the remote repository.

  4. Open a pull request to initiate a code review and discuss changes.

  5. Merge the branch into the main branch after the code review is approved.

  6. Deploy the changes to the production environment.

Git Hygiene

To ensure a smooth and productive workflow, it's essential to practice good "Git hygiene."

Here's are some of the best practices and recommendations to maintain a clean and organised Git repository, promote collaboration, prevent issues, and optimise the version control process.

Repository Organisation

  • Keep repositories focused: Each Git repository should have a clear and well-defined purpose, containing related files and code. Avoid combining unrelated projects or excessive amounts of code within a single repository.

  • Use submodules or subtrees for shared code: If you have code that is reused across multiple repositories, consider using Git submodules or subtrees to manage shared code libraries effectively.

  • Define a consistent branching strategy: Adopt a branching strategy suitable for your project's needs, such as GitFlow, and ensure that all team members understand and follow it consistently.

Committing and Branching

  • Commit regularly and in logical units: Make frequent, granular commits that represent a coherent and logical unit of work. Each commit should focus on a specific change or feature and be accompanied by a descriptive commit message.

  • Create feature branches for new development: Use feature branches to isolate new development work. Branch off from a stable branch (e.g., develop) and merge back once the feature is complete and tested.

  • Keep branches up to date: Regularly update your branches with the latest changes from the main branch to avoid conflicts and ensure a smooth integration process.

Code Reviews and Collaboration

  • Perform code reviews: Encourage regular code reviews by team members to maintain code quality, identify potential issues, and share knowledge. Tools like pull requests can facilitate the code review process.

  • Provide descriptive commit messages and comments: When committing code changes or participating in discussions, ensure that your commit messages and comments provide clear context and explain the reasoning behind the changes.

Repository Maintenance

  • Regularly clean up merged branches: Remove obsolete branches that have been merged into the main branch to keep the repository clean and reduce clutter. However, maintain a clear record of historical branches through tags or documentation.

  • Manage large files and binaries: Avoid adding large files or binaries directly into the repository, as they can bloat the repository size. Consider using Git Large File Storage (LFS) or external file storage solutions for managing such assets.

  • Regularly perform repository maintenance tasks: Optimise the repository size by running periodic Git maintenance commands, such as garbage collection and pruning unused objects.

Documentation and Training

  • Maintain an up-to-date README file: Include essential information about the project, its structure, build instructions, and any specific requirements to help other developers get started quickly.

  • Provide documentation on branching strategies and workflows: Document your team's chosen branching strategy, including guidelines on when and how to create branches, merge changes, and handle conflicts.

  • Conduct Git training sessions: If working with a team of developers, organise training sessions to ensure everyone understands Git fundamentals, best practices, and the specific workflows adopted by the team.

Last updated