StackCards StackCards

← All decks

Git essentials

Daily Git commands, from the first commit to undoing a mistake without panic.

28 cardsBeginnerCode

Download the deck Get StackCards

Open the downloaded file on your iPhone or iPad and choose StackCards. It is also in the app: Library tab, then Add to my library.

What is inside

Start a new repository hereCreates an empty repository in the current folder.
git init
Copy a remote repositoryDownloads the full history and checks out the default branch.
git clone <url>
See what changedShows modified, staged and untracked files.
git status
Stage one fileAdds the file to the next commit.
git add notes.md
Stage only parts of a fileWalks you through each change so you can pick hunks.
git add -p
Commit what is stagedSaves the snapshot with a message.
git commit -m "Add login form"
Fix the last commit messageRewrites the most recent commit. Avoid it once pushed.
git commit --amend
List branchesShows local branches; the current one has a star.
git branch
Create and switch to a branchMakes a branch and moves to it in one step.
git switch -c feature/search
Switch to an existing branchMoves your working folder to that branch.
git switch main
Merge a branch into the current oneJoins the histories, making a merge commit when needed.
git merge feature/search
Download without mergingUpdates your remote-tracking branches and changes nothing else.
git fetch
Fetch and mergeBrings in the remote's new commits and integrates them.
git pull
Upload your commitsSends your branch to the remote.
git push origin main
Publish a new branchPushes it and remembers the remote branch for next time.
git push -u origin feature/search
See history, one line eachA compact log that is easy to scan.
git log --oneline
See history as a graphDraws the branches and merges next to the commits.
git log --oneline --graph --all
Compare unstaged changesShows what changed since the last add or commit.
git diff
Compare staged changesShows exactly what the next commit will contain.
git diff --staged
Unstage a fileTakes it out of the next commit but keeps your edits.
git restore --staged notes.md
Throw away edits in a fileResets it to the last commit. This cannot be undone.
git restore notes.md
Undo a pushed commit safelyAdds a new commit that reverses the old one, so history stays intact.
git revert <commit>
Put work aside for a momentSaves your uncommitted changes and cleans the folder.
git stash
Bring stashed work backReapplies the latest stash and removes it from the list.
git stash pop
Move commits on top of another branchReplays your commits for a linear history.
git rebase main
Copy one commit to this branchApplies the change from a single commit.
git cherry-pick <commit>
Tag a releaseMarks a commit with a name such as a version.
git tag v1.0.0
Who changed this line?Shows the author and commit for each line of a file.
git blame Package.swift