Quick reference
Other cheatsheets
Glossary
working directory/ workspace: the actual files you see and edit
staging area: Place files go after
git add
and beforegit commit
hash: unique reference of any commit or state
branch: One line of work. Different branches can exist at the same time and split/merge.
HEAD: Pointer to the most recent commit on the current branch.
remote: Roughly, another server that holds .git.
origin: Default name for a remote repository.
master: Default name for main branch on Git. Depending on the configuration and service, the default branch is sometimes main. In this lesson we configure Git so that the default branch is called main to be more consistent with GitHub and GitLab.
main: Default name for main branch on GitLab and GitHub. In this lesson we configure Git so that the default branch is called main to be more consistent with GitHub and GitLab.
Commands we use
Setup:
git config
: edit configuration optionsgit init -b main
: create new repository withmain
as the default branch
See our status:
git status
: see status of files - use often!git log
: see history of commits and their messages, newest firstgit graph
: see a detailed graph of commits. Create this command withgit config --global alias.graph "log --all --graph --decorate --oneline"
git diff
: show difference between working directory and last commitgit diff --staged
: show difference between staging area and last commitgit show COMMIT
: inspect individual commits
General work:
git add FILE
:Add a new file
Add a file to staging
git commit
: record a version, add it to current branchgit commit --amend
: amend our last commitgit branch
: show which branch we’re ongit branch NAME
: create a new branch called “name”git restore FILE
: restore last committed/staged version of FILE, losing unstaged changesgit switch --create BRANCH-NAME
: create a new branch and switch to itgit revert HASH
: create a new commit which reverts commit HASHgit reset --soft HASH
: remove all commits after HASH, but keep their modifications as staged changesgit reset --hard HASH
: remove all commits after HASH, permanently throwing away their changesgit merge BRANCH-NAME
: merge branch BRANCH-NAME into current branchgit grep PATTERN
: search for patterns in tracked filesgit annotate FILE
: find out when a specific line got introduced and by whomgit bisect
: find a commit which broke some functionality