Everything here works in Git 2.23 and later. <branch> and <file> are placeholders.
Set up
_10git config --global user.name "Your Name"_10git config --global user.email [email protected]_10git config --global init.defaultBranch main
Start a repository
_10git init # new repo in this folder_10git clone <url> # copy an existing repo_10git clone <url> --depth 1 # latest only
Stage and commit
_10git status # what changed_10git add <file> # stage one file_10git add -p # stage hunk by hunk_10git commit -m "message" # commit what is staged_10git commit --amend # fix the last commit
Branches
_10git switch <branch> # move to a branch_10git switch -c <branch> # create and move_10git branch # list local branches_10git branch -d <branch> # delete a merged branch
Sync with a remote
_10git fetch # download only_10git pull --rebase # fetch, replay yours on top_10git push -u origin <branch> # first push_10git push # later pushes
Look at history
_10git log --oneline --graph # compact_10git log -p <file> # changes to a file_10git diff # unstaged changes_10git diff --staged # staged changes_10git blame <file> # who wrote each line
Undo things
_10git restore <file> # discard changes_10git restore --staged <file> # unstage_10git revert <commit> # commit that undoes one_10git reset --soft HEAD~1 # undo commit, keep work
Set work aside
_10git stash push -m "wip" # shelve changes_10git stash list # see what is shelved_10git stash apply # bring the latest back_10git stash drop # delete the latest