Science and Coding Basics

Version Control with Git Explained for Learners

Understand version control as saved snapshots of your work, how Git records history with commits, and why it helps writers and students as well as programmers.

On this page
  1. The problem it solves
  2. Snapshots, not copies
  3. Key terms
  4. A first session
  5. Why history is useful
  6. It is not only for programmers
  7. What Git is not
  8. Getting started gently

The problem it solves

Anyone who has worked on a document for a while knows the mess: essay.docx, essay_v2.docx, essay_final.docx, essay_final_REALLY.docx. Which is newest? What changed between them? Can you get back the paragraph you deleted last Tuesday?

Version control is a system that answers these questions. It records the history of a set of files so that you can see what changed, when and why, and return to an earlier state if needed. Git is the most widely used version control tool, especially for software. It is free, open-source software, and it works on your own computer without needing a network connection.

Snapshots, not copies

The best mental model is a series of snapshots. At moments you choose, you tell Git to save the current state of your project along with a short message describing the change. Each saved snapshot is called a commit. Together the commits form a timeline that you can browse.

This is different from keeping many copies of a file under different names. Git stores the history in one place, and you can see exactly what changed between any two snapshots. Your working folder always looks tidy, with just the current versions of your files.

Commits are also labeled with who made them and when. A good commit message states the purpose of the change, such as “Add references section” or “Fix wrong total in table”, rather than something vague like “update”.

Key terms

  • Repository: the project folder together with its recorded history.
  • Commit: a saved snapshot with a message.
  • Staging: choosing which changes will go into the next snapshot. Think of it as putting items in a box before you seal and label it.
  • Branch: a separate line of development, so that you can try an idea without disturbing the main version.
  • Merge: combining the changes from one branch into another.
  • Remote: a copy of the repository stored elsewhere, typically on a hosting service, used for backup and collaboration.

A first session

The commands below are typed in a terminal, inside your project folder. Text after a # on a line is a comment that the terminal ignores.

git init                                  # start tracking this folder
git status                                # see what Git notices
git add notes.txt                         # choose a file for the next snapshot
git commit -m "Add first draft of notes"  # save the snapshot with a message

After you edit notes.txt later, you can see what changed with:

git diff

This shows lines that were added or removed since the last commit. When you are happy with the changes, you use git add and git commit again. To read the history:

git log --oneline

This lists your commits, newest first, one line each. If you want to discard unsaved changes to a file and return to the last committed version, recent versions of Git offer git restore notes.txt. Be careful, because that discards your unsaved edits for that file and they generally cannot be recovered.

Git has many more commands and some surprising behavior at first. Most beginners get far with the five or six above. Official documentation and free tutorials are the best place to check details for your own setup.

Why history is useful

You can experiment without fear. If a change makes things worse, you can compare with the last good snapshot or go back to it. Knowing that undo is available makes people more willing to try things.

You can find when a problem began. If something worked last week but not today, the history narrows the search. This is a big help in a debugging mindset, because you can ask what changed rather than guessing.

You can explain your work. A sequence of well-described commits is a record of how a project developed, which is useful for your own memory and for other people reading it.

You can work with others. Several people can work on copies of the same project and merge their changes. Git highlights conflicts when two people changed the same lines, so that someone can decide what to keep. This is also the basis of much collaborative open-source software, where strangers contribute improvements to shared projects.

It is not only for programmers

Git works best with plain text files, such as code, notes, essays written in simple text formats, data files and web pages, because it can show changes line by line. Many students and writers use it for thesis chapters, lecture notes and shared study materials. It is less useful for formats like Word documents, images or videos, where it can store the files but cannot show meaningful line-by-line differences.

Even if you never use Git, the principles are transferable. Saving versions with meaningful descriptions, changing one thing at a time and keeping a record of why you changed it are good habits anywhere. Consistent file naming, with dates in a standard order and clear labels, goes some way toward the same goal for people who prefer ordinary folders.

What Git is not

Git is not a complete backup strategy. If the repository lives only on one computer and that computer fails, the history is lost too. Keeping a remote copy helps, though it is still wise to follow general backup advice. Git is also not a place for secrets: passwords and personal data committed to a repository can remain in its history even after being deleted from the current files, and if the repository is shared they may be exposed.

Getting started gently

Pick a small folder of plain text files, run git init, make a first commit, then change something, check it with git diff and commit again. The vocabulary takes time, and the main reward comes the first time you need to recover something. Good file organization inside the project also pays off as it grows.

The complete guide to science and coding basics

Computational Thinking: Solving Problems Like a Programmer
Read the guide

Keep exploring

Guides from other topics

All topics →