Git explained through one website change
How Git commits, branches, merges and reverts work. Follow one website correction through its history, and see why saving a change does not publish it.
Git is a version control system. It records versions of project files so people can inspect what changed, work on separate changes and bring them together. A repository is the project’s Git record, including its saved history.
Imagine a website button that says “Contcat”. We want to correct it to “Contact”. At the same time, someone else is adding a footer. This invented example follows the two changes through Git, then reverses the spelling correction to show what an undo operation preserves.
What a commit records
The working files are the files we edit. Saving a file in an editor changes that working copy. Git lets us select the content for the next recorded version through a step called staging. A commit records the staged snapshot of the project, together with a message, authorship information and links to earlier commits.
For the spelling fix, we select the change from “Contcat” to “Contact” and commit it with a message explaining the correction. If we edit the file again after staging it, those later edits need staging too if they are to be included. Git records what was staged, rather than automatically taking every edit on the computer.
How branches let work develop separately
A branch is a name that points to a commit. As new commits are made on that branch, the name moves forward to the latest one. Creating a branch starts another line of work from an existing commit; the earlier history is shared.
Before making the correction, we create a branch called fix from the current main branch. We record the spelling correction there. Meanwhile, a separate commit on main adds the footer. The fix branch now points to a version with the corrected button; main points to a version with the footer and the original typo.
These names are examples, and main has no special meaning inside Git. Teams choose which branch holds their combined work. A branch name is a reference to history, so creating one does not duplicate every file in the repository.
What a merge combines
A merge brings changes from one line of history into another. Our two branches have both moved forward, so Git compares their versions with the shared starting version. Here the button and footer edits are in different parts of the file, and the merged result contains both.
This example creates a merge commit with two parents, one from each branch. Some merges only move a branch pointer forward because the incoming history already contains everything on the receiving branch. That is called a fast-forward merge, and it needs no extra merge commit.
If both branches change the same part of a file in incompatible ways, Git can stop with a merge conflict. Someone must decide what the combined version should contain. Even a merge with no conflict needs checking; edits can fit together as text and still produce the wrong behaviour.
What revert leaves in the history
Git’s revert operation can create a new commit that reverses the changes introduced by an earlier commit. The original commit stays in the history alongside the reversal.
To demonstrate it, we revert the spelling-fix commit after the merge. The button returns to “Contcat”, and the new footer remains. We would normally keep a correct spelling fix; this deliberately reverses it so the effect is visible.
Revert does not mean returning the entire project to an old snapshot. Later work may be retained, as the footer is here. It can also conflict with later edits, so the result needs inspection and testing. Reverting a merge has extra choices because that commit has more than one parent; our example reverses the ordinary spelling-fix commit.
Commit, push and deployment do different jobs
A commit records a version in the local repository. A push sends commits and updates branch references in a remote repository, which is another copy hosted elsewhere. GitHub is one service that can host Git repositories.
Deployment makes a selected version available to users. A team may configure a push to trigger tests and deployment, but that automation is separate from Git’s history. A locally saved correction can therefore exist without changing the live website.
Keep each change easy to explain
We would keep the spelling correction in its own commit, with a message that says what changed. A reviewer can inspect it quickly. If the change needs reversing, its scope is clear. Bundling it with a new footer and a redesign makes that decision harder.
The same discipline helps when an AI coding tool makes the edit. Check the proposed changes, run the relevant tests and keep the release decision explicit. Git gives the team a record to inspect; people and checks still have to judge the work.