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.
Sign up to study this deck48 cards, free
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.
- Which Git command creates a new, empty repository in the current directory?git init
- Which Git command copies an existing repository, with its whole history, from a URL?git clone url
- Which Git command shows which files are changed, staged or untracked?git status
- Which Git command stages one file's changes for the next commit?git add file
- 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. - Which Git command records the staged changes as a new commit, with the message given on the command line?git commit -m "message"
- Which Git command replaces the most recent commit with a new one, to fix its message or add to its changes?git commit --amend
- Which Git command shows the commit history of the current branch?git log
- Which Git command shows the commit history with one line per commit?git log --oneline
- Which Git command shows the changes in the working tree that are not staged yet?git diff
- Which Git command shows the changes that are staged for the next commit?git diff --staged
--cached means the same. - Which Git command shows one commit's message and the changes it made?git show commit
- Which Git command shows, for each line of a file, the commit and author that last changed it?git blame file
- Which Git command lists the local branches?git branch
- Which Git command creates a new branch and switches to it?git switch -c branch
The older form is git checkout -b. - Which Git command switches to an existing branch?git switch branch
The older form is git checkout. - Which Git command joins another branch's history into the current branch?git merge branch
- Which Git command replays the current branch's commits on top of another branch?git rebase branch
- Which Git command applies the change from one existing commit onto the current branch as a new commit?git cherry-pick commit
- Which Git command deletes a local branch that has already been merged?git branch -d branch
- Which Git command downloads new commits from a remote without changing your own branches or files?git fetch
- Which Git command fetches from the remote and then integrates the new commits into the current branch?git pull
- Which Git command uploads the current branch's new commits to its remote?git push
- 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
- Which Git command deletes a branch on the remote named origin?git push origin --delete branch
- Which Git command lists the remotes of a repository with their URLs?git remote -v
- Which Git command adds a new remote under a name of your choice?git remote add name url
- 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. - 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. - Which Git command stops tracking a file but leaves it on disk?git rm --cached file
- Which Git command renames or moves a tracked file?git mv old new
- Which Git command sets aside your uncommitted changes to tracked files, leaving those files as they were at the last commit?git stash
- Which Git command lists the changes you have stashed?git stash list
- Which Git command reapplies the most recently stashed changes and removes them from the stash?git stash pop
- Which Git command makes a new commit that undoes the changes of an earlier commit?git revert commit
- Which Git command moves the current branch back to an earlier commit and throws away all changes since?git reset --hard commit
- 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
- Which Git command gives a commit a lasting name of your choice, such as v1.0?git tag name
- Which Git command finds the commit that introduced a bug, by binary search through the history?git bisect
- Which Git command lists where HEAD has pointed recently, which helps to recover commits that seem lost?git reflog
- Which Git command deletes the untracked files in the current directory and below?git clean -f
- 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"
- In Git, what is HEAD?A pointer to the commit you have checked out, usually by way of the current branch.
- 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.
- In Git, what is origin?The default name Git gives to the remote a repository was cloned from.
- In Git, what is the file .gitignore for?It lists patterns for files that Git should leave untracked.
- In Git, what is a remote?Another copy of the repository, usually on a server, that you fetch from and push to.
- 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
- Git: Reference manual git-scm.com/docs
- 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.
