Git: The Basics Of Version Control Management


If you are new to software development or writing software in general one of the first things you should learn along side of your first language is version control. Imagine the following: You are working on a team of software engineers. Each person is contributing to the same project. How are you all working on separate computers yet contributing to the same code? Better yet, how is the code you are writing also magically include the code the rest of the team is writing at the exact same time? Also how is everyone testing their code to make sure it works before magically throwing it in the code everyone else is writing in? What if this introduces a bug? Would each individual have to solve this bug in the exact same way with code they didn’t write? This sounds like an absolute nightmare. This is why software configuration management (SCM) exists. And one of the problems that an SCM called git solves with branching and merging.

Managing Your Code

In this section we will go over some scenarios you might come across when managing versions of code. Think of this as somewhat of a handy git cheat sheet. First we will go over a synopsis of the scenario, followed by a diagram, followed by the prospective git command line entries you will need to implement these changes. Ready? Here we go!

  • You need to create a new branch separate from the main code base in order to implement/test a feature without affecting the main branch.
If anyone has suggestions on a good free online diagram resource PLEASE let me know.

First you need to create a local branch called feature while simultaneously creating a corresponding remote branch. Using the git command line interface enter the following:

git checkout -b feature

You will then write the code for this new feature branch and commit it to the remote repository by entering the following within the git command line:

git add .
git commit -m "feature created"
git push
  • You wish to merge your feature branch back with the main branch. The main branch has developed further since you began working on the feature branch.
MS Paint ftw

say you are currently in the feature branch and have already pushed your commit to this branch after verifying it works. In order to merge this new feature with the main branch you first need to switch to the main branch. Do so by entering the following within the git command line:

git checkout main

It is important to be within the branch you want to merge in to when merging two branches. Now you will need to specify the branch you would like to merge with your current branch. You will also need to push these changes to the repository. Do so by entering the following within the git command line:

git merge feature
git add .
git commit -m "feature merge"
git push


Software development is generally not a solo exercise. Even in the instances it is it is crucial to be able to manage your code as it develops. Version control helps prevent bugs, provides a record of when certain changes were implemented, and allows multiple programmers to collaborate on projects.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store