# Git

> A time machine for code: every change saved, by whom and why.

- Level: Basic
- Topics: Software
- URL: https://tidbit.legios.com.ar/git/
- In Spanish: [Git](https://tidbit.legios.com.ar/es/git/)

**Git** is a program that records the history of a folder of files. Each time you save a set of changes you make a **commit**: a snapshot with a message ("fix login bug"), an author and a date. You can go back to any snapshot, compare two of them, or see who changed a given line and when. Linus Torvalds wrote it in 2005 to manage the Linux kernel, and today it is used for almost all software.

Its second trick is **branches**. A branch is a parallel line of history: you open one to try a new feature, commit freely without touching the main version, and when it works you **merge** it back. Several people can work on different branches of the same project at once, and Git combines the results, flagging the rare lines where two people changed the same thing (a "conflict").

Git itself works on your machine. **GitHub**, GitLab and Bitbucket are websites that host a copy of the repository so a team can share it: `git push` sends your commits there and `git pull` brings down everyone else's. A **pull request** on GitHub is a proposal to merge a branch, with a review conversation attached. Most open source software lives this way.

## An analogy

Track changes in a document, but for a whole folder, with the option of trying an edit in a parallel copy and folding it back in once it is ready.

## Keep in mind

- A commit is a snapshot plus a message; the history is a chain of them.
- Branches let several people work in parallel; merging joins the work.
- Git is the tool; GitHub is one place to host the repository.
- `clone`, `commit`, `push`, `pull` and `merge` are the five commands you will hear most.

## Go deeper

- [Pro Git book (official)](https://git-scm.com/book/en/v2)
- [Git documentation](https://git-scm.com/doc)
- [Git (Wikipedia)](https://en.wikipedia.org/wiki/Git)

## Related terms

- [Bug](https://tidbit.legios.com.ar/bug/): A mistake in software that makes it behave differently from what was intended.
- [Linux](https://tidbit.legios.com.ar/linux/): A free, open source operating system that runs most of the internet's servers.
- [GitHub](https://tidbit.legios.com.ar/github/): A website where teams store their code with Git and work on it together.
- [Code review](https://tidbit.legios.com.ar/code-review/): Having another person read a code change before it becomes part of the product.
- [Open source](https://tidbit.legios.com.ar/open-source/): Software whose code anyone can read, use, change and share.
