Web Development

Git

Git is a free, distributed version control system that keeps the history of changes to a project's files and allows work in parallel branches and the merging of several people's work.

In this post

Git is a version control system used by developers everywhere. It records every change made to a project’s files, who made it and when. It lets you go back to any earlier point and combine the work of several people without them stepping on each other’s toes. It is the tool used by almost every team that writes code, from students to the largest technology companies in the world.

To understand it, think of a shared document with a version history. You can see who changed what, compare it with the previous version and recover a version from a week ago. Git does exactly that with entire projects, with thousands of files, and it does so with a speed and flexibility that have made it the industry standard for more than fifteen years.

Git works like a time machine for any software project. It keeps everything that has been done and lets you go back or work as a team without losing anything.

What is Git?

The name Git is a colloquial British word that means something like an unpleasant person. Its creator, Linus Torvalds, liked to joke about the names of his projects, and he said he named it after himself. It is not an acronym. It is pronounced as it is written, and it is used untranslated around the world. What matters is the function, not the origin of the name.

A version control system solves a universal problem. When several people modify the same files, it is easy for them to overwrite each other’s work, lose changes or lose track of which version is the right one. Before these tools, files were sent by email with names such as final version, final version two and final version for real. Git puts an end to that chaos in an orderly way.

Snapshots, integrity and local operations

Git does not store the differences between versions, but a snapshot of the complete project every time a change is committed, and it reuses the files that have not changed. Each snapshot is identified by a cryptographic fingerprint calculated from its content, so it is impossible to alter the history without Git detecting it. And since every copy has the full history, almost all operations, such as looking at old changes or creating branches, are done on the computer itself, without waiting for a server.

Repository hosting platforms

Git and the platforms that host repositories are often confused. Git is the tool that records changes and runs on each person’s computer. GitHub, GitLab and Bitbucket are cloud services that host repositories and add collaboration features, such as reviewing changes, discussing proposals and automating tests. They resemble a shared warehouse, while Git is the filing system. The choice of service depends on the team and the integrations it needs. All of them allow private repositories, which are essential for client projects. What matters is knowing who has access and turning on multi-factor authentication.

Git compared with other version control systems

Before Git, centralised systems dominated, such as CVS and Subversion, in which the history lived on a single server and each person only had the latest version. Git is distributed, just like Mercurial, which was born the same year with a similar goal. The advantage of a distributed system is that every copy is complete, which allows offline work and means the project does not depend on a single server.

Key Git concepts

Repository and copies

A repository is a project’s folder together with its entire history. Unlike earlier systems, here every person has a complete copy, with the project’s whole past.

This design of Git has an enormous advantage. If the central server disappears, any copy can be used to rebuild it. In addition, you can work offline and synchronise later.

This idea of complete copies is the reason for its robustness. A project with a hundred contributors has, in practice, a hundred backups. For a company, this reduces the risk of losing years of work because of a server failure. But it does not replace normal backups, because a shared mistake spreads to every copy.

Branches for risk-free testing

A branch is a parallel line of work within the project. Imagine you want to try a new feature on your website. You create a branch, make your changes and test them without touching the version visitors use. If it works, you merge it into the main one. If not, you discard it with no consequences. It is like rehearsing a play before opening night.

The three states of a file

Git distinguishes three states for each file in a project. A file is modified when it has been changed but not yet marked to be saved. It is staged when it has been included in the next snapshot with the git add command. And it is committed when it is already part of the history after running git commit. That intermediate staging area lets you choose precisely which changes go into each commit.

How a file moves through the three zones of Git

Basic terminal commands

Day-to-day work relies on a handful of commands. git init creates a repository and git clone copies an existing one. git add and git commit stage and save the changes. git branch and git switch create branches and move between them, and git merge joins them. Finally, git push sends the changes to a remote server and git pull brings in the ones other people have made.

History and recovery

The Git history lets you travel back in time through the project. If an update breaks the website, you can return to the previous state in minutes. If you want to know why something was done a certain way, you read the explanation left by whoever did it. A well-written history is living documentation of the project, valuable when teams change.

The quality of those explanations makes all the difference. Messages such as various fixes are no help at all. Messages that explain what was changed and why help a great deal whoever comes next. Professional teams agree on simple rules for writing them, because they know that a year from now nobody will remember the reasons behind a decision.

Version control in practice and in a team

Version control when working with content management systems

For a simple website built with WordPress, Joomla or PrestaShop, using Git is not essential. But when a custom template or extension is being developed, or several people are working on it, it is highly recommended, and in custom development with Laravel or Symfony it is the norm. It lets you know what changed, when and why, and recover an earlier version if a modification breaks something. Many agencies use it by default, and it offers an additional safety net against human error.

Git also helps to organise the whole workflow of a website. Changes are made first on a test copy, reviewed and only then taken to the live website. This process avoids the dangerous habit of editing files directly on the production server, which is a frequent cause of unexpected outages and of errors that are hard to trace several days later.

It is important to know what should never be stored in a Git repository. Files with database passwords, access keys and private data must not become part of the history. They are kept separately, in a protected place. Many projects include a list of files that are ignored automatically, the .gitignore file, precisely to avoid this kind of mistake and protect the website.

How a team works with Git

The usual workflow of a team that works with Git is orderly. Each task is developed in its own branch, separate from the main version. When it is finished, it is proposed for integration and another person reviews the changes before accepting them. On services such as GitHub this proposal is called a pull request. If everything is correct, it is merged into the main version, and if something fails, it can be undone easily. Every change is signed with its author and date. This method stops two people from overwriting each other’s work and leaves a clear trail of why each decision was made. For a client, it means peace of mind that there is a complete history, that you can go back after a mistake and that knowledge does not depend on a single person.

How to work with branches, review and rollback in Git

Benefits of using version control

The main benefit of version control is safety against mistakes. If a change breaks the website, you go back to the previous version in minutes. Another is traceability, because you know who changed what and why, something valuable in an audit or a dispute. It makes it easy to try ideas without risk and to work in parallel without getting in each other’s way. If you need to apply this in a project, an experienced web developer can help you get it right from the start.

A business that depends on its website should ask whoever maintains it to use version control and to give the business access to its own repository.

Limitations and criticism

Git also has detractors who criticise its complexity. Its command-line interface is not very intuitive, with names that confuse beginners, and undoing certain mistakes requires advanced knowledge. It is not designed for large binary files, such as videos or designs, which bloat the repository, and for those there is the Git LFS extension. And in huge projects, with millions of files, companies such as Microsoft have had to develop their own tools to keep it fast.

Security and checking your repositories

Git and security, a little-known risk

The history is one of Git’s greatest virtues, but also a risk. Everything that is saved stays on record forever. If a developer accidentally publishes a password or an access key inside the project, and later deletes it, the earlier version is still in the history. Anyone with access to the repository could recover it.

This has caused real incidents at many companies. There are cases in which cloud service keys accidentally published in open repositories were found by automated programs within minutes, and used to mine cryptocurrency at the owner’s expense or to access customer data. Today’s platforms detect some of these mistakes and send a warning, but not always in time.

The right response to a secret pushed to Git has two parts. First, preventing secrets from reaching the history, with automated checks and good habits. Second, if it does happen, changing the key immediately, without waiting to investigate. Deleting the file is not enough, because the information is still in the project’s past. Serious companies run drills so that everyone knows how to react quickly.

How to tell whether your team uses it well

A first sign is being able to answer a simple question. What changed on the website last week and who did it? If the answer is that nobody knows, or that you have to ask several people, there is probably no proper version control. With it, the answer appears in seconds, with the date, the author and an explanation of the change.

Another sign is the existence of copies and a central location. Healthy projects have a repository on a reliable service, with access protected by two-step verification and tight permissions. If the only place the code lives is a freelancer’s computer, the company is taking a big risk. The business’s code should always belong to the business.

The third sign of good Git use is discipline. Clear messages, reviews of important changes and no secrets in the history. If you commission development work, ask for access to the repository and check from time to time that it is being updated. It is a simple way to ensure the continuity of the project if you change provider one day, and to have peace of mind about what has actually been built.

The origin of Git in Linux kernel development

Git was born in April 2005 to manage the code of the Linux kernel. Development of the Linux kernel, the program at the base of millions of servers and phones, was managed with a proprietary tool called BitKeeper. The company that offered it allowed the kernel community to use it for free. After a dispute, it withdrew that possibility, and the developers were left without the tool they used every day. Linus Torvalds found no alternative that convinced him in terms of speed, and decided to write his own. As he himself recounted years later, he had a first working version within days. A few months later, the Linux kernel was already being managed with it. The tool was designed for huge projects, with thousands of contributors, which is why it turned out to be very robust.

Since then it has spread all over the world. In 2008 GitHub was founded, a service for hosting projects and collaborating, which helped popularise it. In 2018, Microsoft bought GitHub for a sum running into billions of dollars. Today, when people talk about collaborating on software, they are almost always talking about this tool and the services built around it.

Frequently asked questions

Frequently asked questions about Git

What is Git?

It is a version control system. It records every change made to a project's files, who made it and when. It lets you go back to any earlier point and combine the work of several people, something essential in teams that write code.

Who created Git and why?

Linus Torvalds, the author of Linux, created it in April 2005. The Linux kernel team used a proprietary tool that stopped being offered for free, and Torvalds wrote his own alternative in a few days. Today it is the most widely used tool of its kind in the world.

What is the difference between Git and GitHub?

Git is the tool that keeps the history and runs on each person's computer. GitHub is an online service that hosts Git projects and adds collaboration features. There are other similar services, such as GitLab or Bitbucket. GitHub has belonged to Microsoft since 2018.

What is a Git repository?

It is a project's folder together with its entire history of changes. It can be on your computer, on a server or both. When several people work on the same project, they share a central repository and each one keeps a complete copy of it.

What is a branch in Git?

It is a parallel line of work. It lets you try something new without touching the main version. If it works, it is merged into the main one. If not, it is discarded with no consequences. It is what allows many people to develop different features at the same time safely.

Is Git useful outside programming?

Yes. Any work involving many text files benefits from it, such as documentation, books, configurations or content. It is less convenient with large files such as videos or designs, for which there are better-suited tools. Its value lies in the history and in collaboration.

What security risks does Git have?

The most common is accidentally publishing passwords, keys or private data inside the history. Even if they are deleted later, they remain in the history and can be found. That is why companies use automated checks and rotate keys immediately if they leak.

Do I need Git to maintain a website?

For a simple website built with a content management system, no. But if a template, an extension or a custom application is being developed, or if a team is working on it, it is highly recommended. It lets you know what changed, who changed it and recover an earlier version if a modification breaks something. Many agencies use it by default.

I work with professional version control

I develop your website's code using Git, with an orderly history of every change made.

About the author

Javier Afán

WordPress developer specialised in security, WooCommerce, and hacked website recovery.

I work on WordPress from a technical angle focused on security, architecture, and the decisions that really affect a project's continuity.