Benefits of version control

For everything you need to know about version control, check out Version control – Everything you need to know, on Programming Duck.

Version control provides some benefits that most people would consider essential. Let’s call these "essential benefits". It also provides some minor or "nice-to-have benefits".

Essential benefits of version control

These include things like:

  • Being able to switch between different versions of your code (either different commits or branches), so you can try things out and work on different things at different times.
  • Being able to safely back up your work.
  • Allowing different computers and users to access the codebase.
  • Being able to collaborate with other developers, easily.
  • Being able to resolve code conflicts easily.
  • And much more.

You can obtain all of these benefits with only basic knowledge and basic usage of version control.

Nice-to-have benefits of version control

These include things like:

Help with debugging

If a bug is proving tricky to find, you can reduce the area of code you need to debug by identifying the commit where the bug originated.

You can do this by:

  • Reading the commit history of the codebase and seeing if any commits look suspicious.
  • Checking out past commits one by one and testing them to see if the bug is there.
  • Using the git bisect command.

If you manage to find the "culprit" commit, you may be able to save a lot of time when debugging.

Better code reviews

Sometimes, it’s useful to do a code review on a single commit. For example, you might have already performed a code review on a branch, but requested some additional changes from the author. In this case, it may be a waste of time to re-review all of the changes in the branch. Instead, you can review just the latest commit.

At other times, you may prefer to perform a code review one commit at a time altogether.

Easier reverting / resetting of commits

Sometimes, things just go wrong and you need to revert or reset some commits.

In a critical case (such as a new bug in production), you may just use the "shotgun approach" (revert everything since the last sprint) just to be safe.

However, in less critical situations, it might be better to revert as little as possible so you don’t lose any changes which aren’t faulty.

Well-organised, atomic commits make this easier.

Easier to read and understand the commit history of a project

Sometimes it’s useful to examine the commit history of the project.

This can be for various reasons, such as:

  • Wanting a general overview of the project’s history.
  • Looking through a branch to get an overview of how a feature was developed.
  • Looking at specific commits, to understand why code changed the way it did.
  • Looking at the history of particular files, to understand why, when and how those files have changed. Among other things, knowing these reasons may help you from changing implementations that you shouldn’t change.

Final notes

That’s it for this article.

If you have any feedback, or even counter-arguments, please let me know in the comments.

Next, if you want to know more about version control, as well as how to use it, please see the article Version control – Everything you need to know.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments