This repository contains notes about Git workflows. Below is a curated list of commonly used Git/GitHub commands, followed by a short list of commands commonly used while creating these notes.
git init— Initialize a new Git repositorygit clone <url>— Clone an existing repositorygit status— Show working tree statusgit add <path>/git add .— Stage changesgit restore --staged <path>— Unstage a filegit commit -m "message"— Commit staged changesgit commit --amend— Amend the last commitgit diff— Show unstaged changesgit diff --staged— Show staged changesgit log --oneline --graph --decorate --all— Compact, visual history
git branch— List local branchesgit branch <name>— Create a branchgit switch <name>— Switch to a branchgit switch -c <name>— Create and switch in one stepgit checkout <name>— Older alternative to switchgit branch -d <name>— Delete merged branch locallygit branch -D <name>— Force delete branch locally
git merge <branch>— Merge a branch into the current branchgit merge --no-ff <branch>— Create a merge commit even if fast-forward is possiblegit rebase <base>— Rebase current branch onto another basegit rebase -i <base>— Interactive rebase (reorder/squash/fixup)git rebase --continue/--abort— Continue or abort a rebase
- Edit conflicting files, then:
git add <files>andgit merge --continueorgit rebase --continue - Abort if needed:
git merge --abortorgit rebase --abort
git stash push -m "message"— Stash tracked changes with a messagegit stash list— List stashesgit stash show -p stash@{n}— Show a stash patchgit stash apply stash@{n}— Apply a stash (keep it)git stash pop— Apply and drop the latest stashgit stash push -u— Include untracked files
git remote -v— List remotesgit remote add origin <url>— Add a remotegit fetch— Fetch remote refs without merginggit pull— Fetch and merge remote changes into current branchgit push— Push current branch to its upstreamgit push -u origin <branch>— Push and set upstreamgit push origin --delete <branch>— Delete remote branchgit tag <vX.Y.Z>— Create a lightweight taggit tag -a <vX.Y.Z> -m "message"— Create an annotated taggit push origin <tag>/--tags— Push tags
git show <ref>— Show details about a ref (commit, tag)git blame <file>— Show last modification per linegit reflog— Show reference log of branch tips (recover lost work)
git restore <path>— Restore file from index or commitgit restore --source=<ref> <path>— Restore from a specific commitgit reset --soft <ref>— Move HEAD; keep index and working treegit reset --mixed <ref>— Move HEAD and reset index (default)git reset --hard <ref>— Reset HEAD, index, and working tree (destructive)git revert <commit>— Create a new commit that undoes a commit
git clean -n— Preview removal of untracked filesgit clean -fd— Remove untracked files and directories.gitignore— Configure ignored files
git config --global user.name "Your Name"git config --global user.email "you@example.com"git config --global init.defaultBranch main- Example aliases:
git config --global alias.co switchgit config --global alias.br branchgit config --global alias.ci commitgit config --global alias.st statusgit config --global alias.lg "log --oneline --graph --decorate --all"
These reflect typical commands used while structuring and committing the materials in this repo:
- Repository setup and structure
git initmkdir <topic>/notesand add markdown filesgit add .git commit -m "Add initial notes structure"
- Iterating on content
git statusgit add -p(stage changes interactively)git commit -m "Add notes for <topic>"
- Branching for topics and merging
git switch -c <topic-branch>- Edit/add files under
<topic>/notes/ git add . && git commit -m "Add <topic> notes"git switch maingit merge <topic-branch>git branch -d <topic-branch>
- Conflict practice and resolution (where relevant to lessons)
git merge <branch>→ resolve conflicts in editorgit add <resolved-files>;git merge --continue
- Remote/GitHub integration (if connected)
git remote add origin <repo-url>git push -u origin maingit push -u origin <branch>
- History review and cleanup
git log --oneline --graph --decorate --allgit stash push -m "wip"andgit stash pop(when parking WIP)git tag -a v0.1 -m "first notes set"(optional)
Tip: Use git lg (alias above) to keep an always-useful, compact view of your history.