Expert Insights to Git Savvy

A Guide to Organized Version Control

Master Git version control with this comprehensive guide covering basics, Git Flow, pull requests, and repository management best practices. Whether you're a beginner or experienced developer, discover valuable tips to improve your productivity and collaboration.

Git Organized Version Control
Git Organized Version Control

Get to Know Git

An introduction to Git

Git, the distributed version control system that has become ubiquitous in software development, was first created by Linus Torvalds in 2005. Torvalds was frustrated with the limitations of the centralized version control systems that were available at the time and wanted to create a system that would allow developers to collaborate on projects remotely. Git was the result of his efforts.

In the years since its release, Git has continued to evolve and improve, with contributions from developers all over the world. Today, it is the go-to choice for version control in most software development projects and has become an essential tool for collaborating on code and managing complex software projects. Git's success is a testament to the power of open-source software, and to the passion and dedication of the many developers who have contributed to its development over the years.

Get Distributed

Distributed Version Control

Git is a distributed version control system which means that every developer has a copy of the entire codebase on their local machine. Since each developer has a local copy of the codebase, they can make changes, commit them locally, and even switch between different branches of development without needing an internet connection. This is especially useful for developers who work in remote or disconnected environments, such as on a plane or in a location without reliable internet access. Once they're back online, they can push their changes to the remote repository. This makes it easy to collaborate on code and maintain version history.

Get With the Flow

Managing Multiple Contributors

As software development projects grow in size and complexity, it becomes increasingly important to have a well-defined branching strategy to manage code changes effectively. Without a proper strategy, it can be easy to introduce bugs, slow down development, and make it difficult to manage and maintain the codebase.

Historical Context: The Git Flow branching strategy was created by Vincent Driessen in 2010 with the article: A successful Git branching model

Git Flow solves the problem of having an unorganized and inconsistent branching strategy in software development projects. Before Git Flow, teams would often have their own ad hoc branching strategies that made it difficult for developers to understand what code was in which stage of development, and merge conflicts were common. Git Flow standardized a set of permanent and transitory branches for features and hotfixes, making it easier for developers to collaborate and manage changes.

Permanent Branches

  • MAIN: Stable production code
  • DEVELOP: Latest tested changes

Supporting Branches

  • Feature: New functionality
  • Release: Preparation for deployment
  • Hotfix: Critical production fixes

Get It Together

How the Pull Request Protects the Codebase

In modern software development, projects often have multiple contributors working on different features or fixes simultaneously. Pull Requests (PRs) help manage these contributions by allowing developers to propose changes to the codebase, and to have those changes reviewed and validated by other members of the team before they are merged into the main codebase.

Note: While PRs are not part of Git itself, they were introduced by systems that host Git repositories, as GitHub, Azure DevOps, and others. They have become an essential part of the development process.

A PR Gate is a mechanism used in DevOps to ensure that the merge code is validated with a build and unit tests before the PR is merged into the main codebase. This helps ensure that code quality is maintained and that no regressions or errors are introduced into the system.

Multiple Approvers

Require team review and approval before merging

Work Item Linking

Connect PRs to specific user stories or tasks

Coverage Requirements

Ensure unit test coverage improvements // Repository Organization Section

Get Organized

How to Keep Your Repositories from Going Rogue

Take Control: End the war against rogue code repositories! Let's explore strategies to keep your repositories organized and prevent them from turning to the dark side.

You have likely battled your fair share of rogue code on your hard drive. It's time to end this war once and for all! Let us explore some strategies to keep your repositories in line and prevent them from going rogue. Let's take control of our code clones before they turn to the dark side and start a war.

Folder Structure Strategy

When cloning a repository from platforms like GitHub or Azure DevOps, create a folder structure on your local machine that reflects the platform you're using. For example:

C:\GitHub\{username}\{repository}

This helps you keep track of where code is stored and avoid cluttering the file system with unorganized code.

Git Organized Folder Structure
Git Organized Folder Structure

Branching Best Practices

  • Create feature branches: Always work on feature branches, never directly on develop
  • Sync regularly: Keep your branches up to date with remote repository
  • Fork when contributing: Create your own copy for external projects
  • Pull latest changes: Regularly update your fork from original repository

Daily Workflow

  • Stay current: Keep local repository synced with develop branch
  • Daily updates: Update feature branch with develop at least once daily
  • Never work on develop: Always use feature branches for development
  • Limit conflicts: Regular syncing prevents merge conflicts

Repository Maintenance

Keeping repositories (Origin/remote and local) in sync within Visual Studio can be confusing. Visual Studio does not always update all the remote branches when they are deleted.

Git Organized Visual Studio Setting
Visual Studio Git Settings
Command Line Solution: Use Git command line to prune deleted remote branches:
$ git remote prune origin
Platform Options

GitHub and Azure DevOps are not the only hosted Git repositories available. Other popular options include GitLab, Bitbucket, GitKraken, SourceForge, and AWS CodeCommit. Each platform has its own unique features and benefits, so evaluate your needs and choose the one that best fits your workflow. // Branching Red Flags Section

Branching Red Flags

A quick review of your repository can help you identify potential issues that could cause headaches in the future. Here are the warning signs to watch for:

Naming & Structure Issues

Improper Named Branches

There should only be 2 branches at the root: "Develop" and "Master" (or Main). All other branches should be organized in folders (feature, hotfix, release, [Users]).

Out of Date Branches

When a branch is more than 10-20 commits behind, there's a high probability of merge conflicts. Monitor the commits behind/ahead column in your repository.

Process Violations

Pull Requests Behind Develop

All pull requests should be 0 commits behind develop branch to avoid creating untested code states during merge.

Multiple Release Branches

Ideally, only one deployment branch at a time. Multiple release branches should be rare and short-lived.

Timing Issues

OLD Pull Requests

Pull requests taking over a week should be abandoned. Create a new PR when the feature branch is ready for review.

Documentation Issues

Unlinked Work Items

Link at least one work item to each pull request. This small effort makes tracking work much easier later.

Best Practice: Following these file management strategies ensures organized and efficient collaboration with remote repositories.

Conclusion: Master Your Git Workflow

Git is a powerful tool that allows developers to track changes in their code, collaborate with others, and manage projects efficiently. Success comes from following established best practices and continuous learning.

Git Flow Strategy

Implement consistent branching strategies for organized development

Pull Request Protection

Use code reviews and automated gates to maintain quality

Team Collaboration

Foster effective teamwork through organized repository management

Keep Learning and Growing

Using Git requires ongoing learning and practice. As you encounter new situations and challenges, don't hesitate to ask questions, reach out to colleagues, or seek help from online communities. With time and experience, you can become a Git master and streamline your development process like never before.

Thank you for taking the time to read this article. I hope it has been informative and helpful in improving your Git practices.

Ready to "git" organized and improve your workflow? Start implementing these strategies today!