All ready-made decks

Git commands

The Git commands that cover everyday work: saving changes, branching, working with a remote and undoing mistakes. Plus the handful of terms you need to follow the manual.

Already have an account? Log in and add it from here.

Every card in the deck

Shown here with the answers. When you study, Owl shows you the question, waits for you to recall the answer, and brings each card back just before you would forget it.

  1. Which Git command creates a new, empty repository in the current directory?
    git init
  2. Which Git command copies an existing repository, with its whole history, from a URL?
    git clone url
  3. Which Git command shows which files are changed, staged or untracked?
    git status
  4. Which Git command stages one file's changes for the next commit?
    git add file
  5. Which Git command stages every change in the current directory and below?
    git add .
    git add -A stages every change in the whole working tree.
  6. Which Git command records the staged changes as a new commit, with the message given on the command line?
    git commit -m "message"
  7. Which Git command replaces the most recent commit with a new one, to fix its message or add to its changes?
    git commit --amend
  8. Which Git command shows the commit history of the current branch?
    git log
  9. Which Git command shows the commit history with one line per commit?
    git log --oneline
  10. Which Git command shows the changes in the working tree that are not staged yet?
    git diff
  11. Which Git command shows the changes that are staged for the next commit?
    git diff --staged
    --cached means the same.
  12. Which Git command shows one commit's message and the changes it made?
    git show commit
  13. Which Git command shows, for each line of a file, the commit and author that last changed it?
    git blame file
  14. Which Git command lists the local branches?
    git branch
  15. Which Git command creates a new branch and switches to it?
    git switch -c branch
    The older form is git checkout -b.
  16. Which Git command switches to an existing branch?
    git switch branch
    The older form is git checkout.
  17. Which Git command joins another branch's history into the current branch?
    git merge branch
  18. Which Git command replays the current branch's commits on top of another branch?
    git rebase branch
  19. Which Git command applies the change from one existing commit onto the current branch as a new commit?
    git cherry-pick commit
  20. Which Git command deletes a local branch that has already been merged?
    git branch -d branch
  21. Which Git command downloads new commits from a remote without changing your own branches or files?
    git fetch
  22. Which Git command fetches from the remote and then integrates the new commits into the current branch?
    git pull
  23. Which Git command uploads the current branch's new commits to its remote?
    git push
  24. Which Git command pushes a new branch to the remote named origin and sets it as the branch's upstream?
    git push -u origin branch
  25. Which Git command deletes a branch on the remote named origin?
    git push origin --delete branch
  26. Which Git command lists the remotes of a repository with their URLs?
    git remote -v
  27. Which Git command adds a new remote under a name of your choice?
    git remote add name url
  28. Which Git command takes a file out of the staging area but keeps its changes in the working tree?
    git restore --staged file
    The older form is git reset with the file's name.
  29. Which Git command throws away the unstaged changes to a file in the working tree?
    git restore file
    The older form is git checkout -- with the file's name.
  30. Which Git command stops tracking a file but leaves it on disk?
    git rm --cached file
  31. Which Git command renames or moves a tracked file?
    git mv old new
  32. Which Git command sets aside your uncommitted changes to tracked files, leaving those files as they were at the last commit?
    git stash
  33. Which Git command lists the changes you have stashed?
    git stash list
  34. Which Git command reapplies the most recently stashed changes and removes them from the stash?
    git stash pop
  35. Which Git command makes a new commit that undoes the changes of an earlier commit?
    git revert commit
  36. Which Git command moves the current branch back to an earlier commit and throws away all changes since?
    git reset --hard commit
  37. Which Git command moves the current branch back to an earlier commit but keeps the later changes in the working tree, unstaged?
    git reset commit
  38. Which Git command gives a commit a lasting name of your choice, such as v1.0?
    git tag name
  39. Which Git command finds the commit that introduced a bug, by binary search through the history?
    git bisect
  40. Which Git command lists where HEAD has pointed recently, which helps to recover commits that seem lost?
    git reflog
  41. Which Git command deletes the untracked files in the current directory and below?
    git clean -f
  42. Which Git command sets the name recorded on your commits, for all of your repositories on this computer?
    git config --global user.name "Your Name"
  43. In Git, what is HEAD?
    A pointer to the commit you have checked out, usually by way of the current branch.
  44. In Git, what is the staging area (also called the index)?
    The place where you put together the changes that will go into the next commit.
  45. In Git, what is origin?
    The default name Git gives to the remote a repository was cloned from.
  46. In Git, what is the file .gitignore for?
    It lists patterns for files that Git should leave untracked.
  47. In Git, what is a remote?
    Another copy of the repository, usually on a server, that you fetch from and push to.
  48. In Git, what is a merge conflict?
    What you get when two branches changed the same part of a file in different ways, and Git can't combine them on its own.

Sources

  1. Git: Reference manual git-scm.com/docs
  2. Pro Git, second edition, by Scott Chacon and Ben Straub git-scm.com/book/en/v2

Owl keeps the calendar. You do the remembering.

Already have an account? Log in and add it from here.