## glossary

What is Git?

Git is a distributed version control system created in 2005 by Linus Torvalds to manage the development of the Linux kernel. It records the complete history of changes in a project, letting you return to any earlier state, work in parallel and understand who changed what and why.

The word distributed is what sets it apart from earlier systems. Every developer holds a full copy of the repository, with the entire history. That allows working offline, creates natural backups and makes operations like browsing the history instantaneous, because everything lives on local disk.

The three states of a file

Understanding this flow clears up most of the early confusion. A modified file passes through three areas before entering the history:

From edited file to commit
 working          staging          local
directory   -->    area    -->   repository  -->  remote
(modified)      (git add)      (git commit)     (git push)

git status         # what state each file is in
git diff           # changed but not yet staged
git diff --staged  # staged, waiting for a commit

Everyday commands

The basic working cycle
git clone <url>                # downloads a repository
git checkout -b feat/carrinho  # creates and switches to a branch
git add .                      # moves changes to staging
git commit -m "adiciona carrinho"
git pull --rebase              # brings in the remote without an extra merge
git push -u origin feat/carrinho

git log --oneline --graph      # visualizes the history
git blame arquivo.ts           # who changed each line

Undoing: each case has its own command

This is the area that causes the most anxiety. The right choice depends on how far the change has already traveled:

  • git restore arquivo — discards local changes that have not been staged yet.
  • git restore --staged arquivo — removes it from staging without losing the changes.
  • git commit --amend — fixes the message or the content of the last commit, if it has not been pushed yet.
  • git revert <hash> — creates a new commit that undoes another one. Safe on shared branches.
  • git reset --hard <hash> — rewrites history and discards changes. Dangerous: use it only locally.

The rule that prevents accidents: never rewrite history that has already been shared. If the commit was pushed and other people have pulled it, use revert, not reset.

Commit best practices

Small commits focused on a single logical change make review easier and allow surgical reverts. The message should explain why, not what — the diff already shows the what. Conventions like Conventional Commits (feat:, fix:, docs:) standardize the history and make it possible to generate changelogs automatically, which ties directly into semantic versioning.

## faq

Frequently asked questions

What is the difference between Git and GitHub?

Git is the version control system that runs on your machine. GitHub is a web platform that hosts Git repositories and adds collaboration — pull requests, issues, CI/CD and code review. Alternatives include GitLab and Bitbucket. You can use Git without any of them.

Merge or rebase: which one should I use?

Merge preserves the real history, including the fork point, and is safe on shared branches. Rebase replays your commits on top of the current base, producing a linear, more readable history. The common recommendation is rebase on local branches before opening the PR, and merge to integrate into the main branch.

How do I recover a commit I deleted?

Use git reflog, which records every recent position of HEAD, even the ones removed from the visible history. Find the hash of the commit you want and go back with git reset --hard, or create a branch from it. Git rarely discards data for real before garbage collection runs.