TodayTools

Git flashcards

Save every version of your code, undo any mistake and ship with a team without stepping on each other.

Donate
Beginner friendly, starts from zero
Section
How to study
0
GitStart from zero · 1 of 12

What is Git, in one plain sentence?

A tool that saves the history of a project, so you can see every change, go back to any earlier version and work with others on the same files.

Undo for a whole project, forever.

All topics

Git at a glance

Git saves the full history of a project, so you can go back to any version and work with a team safely.

Like a photo album of your project: each step gets a captioned photo you can flip back to.

Words you will meet

Repository
Your project folder plus its saved history
Commit
One saved snapshot of the files with a short message
Staging area
A waiting tray for changes that go into the next commit
Branch
A separate line of work that does not touch the main version
Merge
Join a finished branch back into another one
Remote
A shared copy of the repo on a server
Push and pull
Send your commits to the remote, or bring others' commits to you
Diff
A view of exactly which lines changed

The steps

  1. 1. Start from zero (12 cards): What Git is, the key words in plain English, and your first commit.
  2. 2. Core basics (16 cards): Snapshots, the three areas, branches and your first push, the way teams really use them.
  3. 3. Next steps (16 cards): Conflicts, undoing anything safely, stash, rebase and a pull request workflow you will use every week.
  4. 4. Go deeper (17 cards): History surgery, recovery, bisect, internals, signing, monorepo speed and team-scale conventions.
All 12 cards in Start from zero
What is Git, in one plain sentence?
A tool that saves the history of a project, so you can see every change, go back to any earlier version and work with others on the same files.
How did people manage versions before Git?
They copied folders and named them final, final-2, final-really. Nobody knew which was newest, and two people editing the same file wiped out each other's work.
Where do you already meet the idea behind Git?
Version history in an online document, where you can open yesterday's copy, or the undo list in a drawing app. Git does this for every file in a project.
What is an everyday picture for how Git works?
A photo album of your project. Each time you are happy with a step, you take a photo with a short caption. You can always flip back to any old photo.
What do repository and commit mean?
A repository (repo) is your project folder plus its saved history. A commit is one saved snapshot of the files with a short message saying what changed.
What is the staging area?
A waiting tray where you place the changes you want in your next commit. You choose what goes in, so one commit holds one clear change.
What do branch and merge mean?
A branch is a separate line of work, so you can try something without touching the main version. Merge joins a finished branch back into the main line.
What are a remote, push and pull?
A remote is a copy of the repo on a server (a computer online) that the team shares. Push sends your commits up to it. Pull brings other people's commits down to you.
What are a host, a pull request and a diff?
A host is a website that keeps remotes, such as GitHub or Bitbucket. A pull request asks teammates to review your branch before it is merged. A diff shows exactly which lines changed.
What do you need before starting?
Git installed (it comes with many computers) and a terminal, a text window where you type commands. A free host account helps later for sharing.
What is a first tiny win with Git?
git init starts a repo in your folder, git add puts a file in the staging area, and git commit -m saves the snapshot with a message.
What will you be able to do after this topic?
Save clean commits, undo mistakes, work on branches, merge them, share your work through a remote and fix the common errors teams hit every week.
Git cheatsheet

Daily loop

  • git status -sb Short status with branch and ahead/behind
  • git add -p Stage changes hunk by hunk
  • git diff --staged Review what will be committed
  • git commit -m "subject" Commit staged changes
  • git pull --rebase Update and keep history linear
  • git push -u origin HEAD Push current branch and track it

Branches

  • git switch -c feat/x origin/main New branch from latest main
  • git switch - Jump back to previous branch
  • git branch -vv Branches with upstream and ahead/behind
  • git rebase -i origin/main Squash, reword, reorder before PR
  • git merge --ff-only origin/main Update main, never create a merge
  • git fetch --prune Drop refs deleted on the server

Undo

  • git restore <file> Discard unstaged edits
  • git restore --staged <file> Unstage, keep edits
  • git commit --amend --no-edit Add staged changes to last commit
  • git reset --soft HEAD~1 Undo last commit, keep it staged
  • git revert <hash> Undo a shared commit with a new one
  • git reflog Find any commit HEAD has visited
  • git stash push -u -m "msg" Shelve all changes incl. new files

Investigate

  • git log --oneline --graph --all Visual history of every branch
  • git log -S "text" -- path Commits that added or removed text
  • git log main..feature Commits on feature not on main
  • git blame -w -C -L 10,30 file Who changed lines, ignoring moves
  • git show <hash> --stat Files changed in a commit
  • git bisect run <test-cmd> Auto-find the breaking commit

Remote and release

  • git push --force-with-lease Force push only if nobody else pushed
  • git tag -a v1.4.0 -m "msg" Annotated release tag
  • git push --follow-tags Push commits and their annotated tags
  • git cherry-pick -x <hash> Copy one commit, note the source
  • git worktree add ../dir branch Second working folder, same repo
  • git clone --filter=blob:none URL Fast clone, fetch files on demand
Donate