Glossary

Git

Git is a free, distributed version control system that records your project as a history of snapshots, so you can branch, merge, compare and undo changes. Its own manual describes it as a fast, scalable, distributed revision control system, and its man page title is "the stupid content tracker". Linus Torvalds started it in 2005 for Linux kernel development. Git is not GitHub: GitHub is a hosting service built around Git repositories.

How it works

Git stores the project as snapshots, not as a list of per-file changes. Each commit records what the tracked files look like at that moment. Files that have not changed are not stored again, only linked to the identical earlier copy.

  • Distributed: every clone holds the full history. Most operations, such as viewing the log or committing, use only local files and need no network.
  • Commit IDs: by default each object is named by a SHA-1 hash, a 40-character hexadecimal string computed from its contents. git init also accepts --object-format=sha256 for SHA-256 repositories. A commit ID looks like 24b9da6552252987aa493b52f8696cd6d3b00373. git log --oneline shows an abbreviated form, 7 characters in the run below.
  • Three states: a file is modified, staged or committed. The working tree holds your edits, the staging area holds what the next commit will contain, and the Git directory holds the committed history.
  • Branches: a branch is a lightweight movable pointer to a commit, so creating one is nearly instantaneous. A merge combines two lines of history.
  • Default branch name: git init creates master unless you set init.defaultBranch or pass -b. The git-init documentation says the default will change to main when Git 3.0 is released.
git init -b main
echo hello > a.txt
git add a.txt
git commit -m "Add a.txt"
git log --oneline
git hash-object a.txt
git rev-parse HEAD | awk '{print length($0)}'
git cat-file -t HEAD

Output from Git 2.43.0:

Initialized empty Git repository in /tmp/demo/.git/
[main (root-commit) 4edad1e] Add a.txt
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
4edad1e Add a.txt
ce013625030ba8dba906f756967f9e9ca394464a
40
commit

The commit ID 4edad1e will differ on your machine because it includes your name and the time. The blob hash ce01362... for the file content hello plus a newline is the same everywhere.

What does Git stand for?

Git does not officially stand for anything. The README in the Git source tree says Linus Torvalds picked the name and offers readings by mood: a random pronounceable three-letter word, a slang insult, "global information tracker" when it works, and a rude phrase when it breaks. He called the tool "the stupid content tracker", which is still the git man page title. The project began in 2005, after BitKeeper, the proprietary tool the kernel had used since 2002, lost its free-of-charge status.

Common pitfalls

  • Committing secrets or build output: once a file is committed, it lives in history even if you delete it in a later commit. Add node_modules, .env and build folders to .gitignore before the first add.
  • Expecting the default branch to be main: older and unconfigured installs create master, which can break CI scripts that assume main. Run git init -b main or set init.defaultBranch.
  • Committing without identity: git commit stops with "Author identity unknown" and "Please tell me who you are" until user.name and user.email are set. Set them once with git config --global.
  • Confusing the staging area with the working tree: git commit saves only staged changes. In a test, editing a tracked file and running git commit -m without git add or -a committed nothing, and git status -sb still showed M for the file.
  • Treating Git as a backup: commits live in the .git folder of your local clone until you push. Delete the project folder with no remote copy, and the history goes with it.
  • Empty folders: Git tracks file contents, so an empty directory is not recorded: git add on one printed nothing and git status did not list it. Add a placeholder file such as .gitkeep.

Related terms

  • SHA-1 — the hash function Git uses to name commits and other objects
  • SSH key — the usual way to authenticate when pushing to a remote

See also

  • Tool: .gitignore Generator — generates .gitignore files for any tech stack
  • Cheatsheet: Git Commands Cheatsheet — everyday commands for committing, branching and undoing