Git flashcards
Save every version of your code, undo any mistake and ship with a team without stepping on each other.
Beginner friendly, starts from zero
0
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. Start from zero (12 cards): What Git is, the key words in plain English, and your first commit.
- 2. Core basics (16 cards): Snapshots, the three areas, branches and your first push, the way teams really use them.
- 3. Next steps (16 cards): Conflicts, undoing anything safely, stash, rebase and a pull request workflow you will use every week.
- 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 initstarts a repo in your folder,git addputs a file in the staging area, andgit commit -msaves 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 -sbShort status with branch and ahead/behindgit add -pStage changes hunk by hunkgit diff --stagedReview what will be committedgit commit -m "subject"Commit staged changesgit pull --rebaseUpdate and keep history lineargit push -u origin HEADPush current branch and track it
Branches
git switch -c feat/x origin/mainNew branch from latest maingit switch -Jump back to previous branchgit branch -vvBranches with upstream and ahead/behindgit rebase -i origin/mainSquash, reword, reorder before PRgit merge --ff-only origin/mainUpdate main, never create a mergegit fetch --pruneDrop refs deleted on the server
Undo
git restore <file>Discard unstaged editsgit restore --staged <file>Unstage, keep editsgit commit --amend --no-editAdd staged changes to last commitgit reset --soft HEAD~1Undo last commit, keep it stagedgit revert <hash>Undo a shared commit with a new onegit reflogFind any commit HEAD has visitedgit stash push -u -m "msg"Shelve all changes incl. new files
Investigate
git log --oneline --graph --allVisual history of every branchgit log -S "text" -- pathCommits that added or removed textgit log main..featureCommits on feature not on maingit blame -w -C -L 10,30 fileWho changed lines, ignoring movesgit show <hash> --statFiles changed in a commitgit bisect run <test-cmd>Auto-find the breaking commit
Remote and release
git push --force-with-leaseForce push only if nobody else pushedgit tag -a v1.4.0 -m "msg"Annotated release taggit push --follow-tagsPush commits and their annotated tagsgit cherry-pick -x <hash>Copy one commit, note the sourcegit worktree add ../dir branchSecond working folder, same repogit clone --filter=blob:none URLFast clone, fetch files on demand