DEV Community

Cover image for How does Git work?
BPB Online
BPB Online

Posted on • Updated on

How does Git work?

Git is a free and open-source version control system originally created by Linus Torvalds, who wrote Linux; he released Git around 2005. Git immediately became popular among developers because it was free, open-source, and distributed, unlike the other version control systems of the time, which were SVN and CVS.

When we say Git is distributed, it means that every user or developer has their own local repository with a full history of their code on their local disk. Although this makes the initial clone of the repository slower, it has many advantages to compensate for this, like portability, privacy, and the ability to work offline. Subsequent Git operations such as commit, blame, diff, merge, and log are also faster.

Git is as much a collaboration tool as it has excellent support for branching, merging, and rewriting repository code history, which has led to many innovative and powerful workflows and tools. However, the problem with Git is that it is not so much difficult as unintuitive; learning the terms does not come easily for most people. Nonetheless, Git is the most widely used version control system in the world today and is considered the modern standard for software development.

To get to grips with Git, we need to first try to understand the opaque language and terms. Here is a basic overview of the most common Git tasks and their associated terms, which also gives us a glimpse into how Git works:

  • You need to create a repository (project) with Git.
  • You Clone (copy) the remote repository to your local machine.
  • You then add files to your local repo (repository) and "Commit" (save) the changes.
  • To advertise your local changes to the team, you Push" your changes to the main branch in the Git repo.
  • You make a change to your file with a Git and commit the change.
  • You Pull other people's code or changes to your local machine from the Git repo.
  • You Create a branch (a new version of the code tree), make a change, and commit the change to prevent damaging the master tree.
  • You Open a pull request (propose changes to the main branch).
  • When the team agrees that the code is good, they Merge your branch with the main branch.

At its core, Git is a valuable code source control system, but it has changed the way we think about code. It is the inspiration behind the latest development and operations initiatives, such as code-based infrastructure and operational procedures that rely on Git as the single source of truth. Git has also inspired GitOps, which is an evolution of Infrastructure as Code (IaC) and DevOps best practices, which are based upon Git's practice of using pull requests to verify and automate the deployment of system infrastructure. However, at the heart of Git or any other software versioning or control system is the trust in the integrity of the repository, and this requires strict access control from the ground up.

Hope this was helpful.

Discussion (1)

tracygjg profile image
TGJ Gilmore • Edited on

You might find the Git Parable by Tom Preston-Werner of interest.