fbpx

EXPLORE OUR

A brief overview of how Git works

Github logo

ARTICLE SUMMARY

Version control is one of the most important skills if you deal with software. It is one of the skills that you will use daily, and knowing the basics of how it works, makes it easier to understand and master. This article is a high-level explanation of how Git works.

If you work in tech, whether you are a software developer, a data scientist, or a programmer, you will need to write, debug and maintain code. Currently, the way to keep track of code maintenance across teams is by using Git. Git is a version control tool that allows developers to track changes from different contributors. Git is one of the reasons open-source software is a possibility today. That’s why mastering version control is essential for working with any software.

WHAT IS VERSION CONTROL?

Version control is a name we call a particular type of software designed to help programmers track any specific application source code changes.

There are two types of version control systems, centralized and distributed. In centralized systems, the code files and the information about the contributors are stored on the same server. While in distributed systems, copies of the files are stored on every contributor’s machine.

Git is a distributed version control system based on a concept called repositories. It was created by Linux’s creator Linus Torvalds to manage the Linux kernel source code.

CONCEPTS YOU NEED TO KNOW TO USE GIT.

Repositories

Repositories (or repos) are the primary building block of Git. A repository is a folder in your computer with different types of files and their “last modified” dates.

In repos, all versions of the content are stored in the repo, that is, every time a file is modified and then saved. The repo is where the content is stored, called the working directory.

For example, suppose you have several doc files in a specific directory on your hard drive. In that case, this directory will be the repo, and the files inside it are the content. Say you opened one of those files to edit it; the application where you edit the doc is the working directory.

Every time you edit a doc, you create a new version; once you save the latest modifications, it’s called a commit.

Git contains many commands to deal with and manipulate repos. Commands such as init, add, commit, branch, log, etc., help you perform a specific task.

Branching

A series of changes create a new version; the pointer to that version is called a branch. Branches allow developers in different physical locations to contribute to the same codebase without affecting each other’s work. And if the changes are not conflicting, they can be added together and create a new version of the repo.

In Git, a branch consists of an ordered list of changes known as the changeset. These changes are sorted as they are applied to the current version of the files.  

Git commands

Merging

After a developer finishes working on one of the branches, they can add these changes to the main branch using merge operations. Merging takes the contents of two branches and merges them into one.

Based on the type of changes done and the content of the branches, there are three types of merges:

  1. Fast forward merge: If the main branch was not touched since the second branch was created, Git adds the second branch updates to the main. Since there are no other changes in the main branch, this type is called a fast-forward branch because it moves the main branch forward to the state of the second branch.
  2. No-conflict merges: If both branches have changed. Still, these changes are independent and don’t conflict; Git automatically applies all changes to the main branch.
  3. Conflicting merge: If the changes in the two branches conflict, Git leaves the results. In this case, the user has to either solve the conflict or abort the merge.

Git checks for conflict by trying to find the locations in content where a change has occurred; if the two branches have changes in the same location, and these changes are dependent, Git will stop and raise a conflict flag. But, if the changes are independent, Git will perform a fast-forward merge.

More Git commands
Image by the author of basic merge-related Git commands

Understanding the basics of how Git works is critical knowledge for any developer or programmer. Since we work with large codebases daily, we need to know on a high level how Git works and how we can utilise it to make our workflow more efficient. However, memorising and understanding the core mechanics of version control is a skill you keep building as you progress through your career. Basically, the more you use Git, the more you get used to Git.

CAREER BUILDING RESOURCES
FOLLOW US ON SOCIAL
RELATED CONTENT
RELATED CATEGORIES
JOIN OUR COMMUNITY

RELATED ARTICLES

In an era of rapid technological advancement, the tech industry leads in innovation and growth. Here, Sheila Flavell CBE, COO of FDM Group, discusses the...
Join us for a captivating discussion as we delve into the world of tech at Dunelm with two remarkable women from the company's tech department....
Discover how Capco's #BYAW movement is revolutionizing workplace culture, empowering individuals to embrace authenticity and driving innovation through diversity and inclusion.
Meet Isabelle Tucker, Founder and Creative Director of Klioh Studio. Isabelle is advocate for empowerment in the workplace and a modern work culture. She is...