Cheat Sheet - Linux: /linux/ - CLI: /linux/cli/ - locate vs type vs which vs whereis: /linux/cli/locate-vs-type-vs-which-vs-whereis/ - make: /linux/cli/make/ - awk: /linux/cli/awk/ - find: /linux/cli/find/ - grep: /linux/cli/grep/ - pgrep: /linux/cli/pgrep/ - ps: /linux/cli/ps/ - pstree: /linux/cli/pstree/ - trap: /linux/cli/trap/ - xargs: /linux/cli/xargs/ - Shell: /linux/shell/ - BASH_SOURCE: /linux/shell/bash-source/ - Redirection: /linux/shell/redirection/ - Special Variables: /linux/shell/special-variables/ - Scripting Tips: /linux/shell/script-tips/ - set -o vi: /linux/shell/bash-vi-mode/ - Shell Processing Order: /linux/shell/process-order/ - What are Interactive and Login Shells?: /linux/shell/interactive-login/ - Double Quote Expansion: /linux/shell/shell-expansion/ - System Programming: /linux/system-programming/ - File I/O: /linux/system-programming/file-io/ - Process: /linux/system-programming/process/ - Shared Libraries: /linux/system-programming/shared-libraries/ - Kernel: /linux/kernel/ - Go: /programming/go/ - Concurrency: /programming/go/concurrency/ - CSP (Communicating Sequential Processes) and Channels: /programming/go/concurrency/csp/ - Channel: /programming/go/concurrency/channel/ - Select: /programming/go/concurrency/select/ - sync: /programming/go/concurrency/sync/ - Concurrency Patterns: /programming/go/concurrency/patterns/ - Goroutines and the Go Runtime: /programming/go/concurrency/runtime/ - Standard Library: /programming/go/std/ - os: /programming/go/std/os/ - context: /programming/go/std/context/ - io: /programming/go/std/io/ - json: /programming/go/std/json/ - net/http: /programming/go/std/net-http/ - slog: /programming/go/std/slog/ - testing: /programming/go/std/testing/ - time: /programming/go/std/time/ - Ellipsis (...): /programming/go/ellipsis/ - error: /programming/go/error/ - Function: /programming/go/function/ - Go Tool: /programming/go/tool/ - Interface: /programming/go/interface/ - Map: /programming/go/map/ - Package and Module: /programming/go/package-module/ - Pointer: /programming/go/pointer/ - Slice: /programming/go/slice/ - String: /programming/go/string/ - Switch: /programming/go/switch/ - Comparison: /programming/go/comparison/ - defaultdict: /programming/python/collections/defaultdict/ - heapq: /programming/python/collections/heapq/ - @cache: /programming/python/cache/ - abc: /programming/python/abc/ - bisect: /programming/python/bisect/ - Type Hints: /programming/python/type-hints/ - Passing Mechanism: /programming/python/passing-mechanism/ - uv: /programming/python/uv/ - *args and **kwargs: /programming/python/args-kwargs/ - re: /programming/python/re/ - C: /programming/c/ - Pointers and Arrays: /programming/c/pointer/ - Syntax Basics: /programming/c/syntax-basics/ - static: /programming/c/static/ - Bit Manipulation: /programming/c/bit-manipulation/ - C vs C++: /programming/c/c-vs-cpp/ - stdatomic: /programming/c/stdatomic/ - C++: /programming/cpp/ - RAII (Resource Acquisition Is Initialization): /programming/cpp/raii/ - Copy Elision & Move Semantics: /programming/cpp/copy-elision-and-move-semantics/ - Most Vexing Parse & In-Class Initializer: /programming/cpp/most-vexing-parse/ - C++ Keywords Reference: /programming/cpp/keywords/ - C++ Primer: /programming/cpp/primer/ - Variables and Basic Types: /programming/cpp/primer/variables-and-basic-types/ - Expressions: /programming/cpp/primer/expressions/ - Type Conversions and Casts: /programming/cpp/primer/type-conversions-and-casts/ - Statements: /programming/cpp/primer/statements/ - Functions: /programming/cpp/primer/functions/ - Classes: /programming/cpp/primer/classes/ - The IO Library: /programming/cpp/primer/io-library/ - STL: /programming/cpp/primer/stl/ - Lambda Expressions: /programming/cpp/primer/lambda/ - Smart Pointers: /programming/cpp/primer/smart-pointers/ - Copy Control: /programming/cpp/primer/copy-control/ - Overloaded Operations and Conversions: /programming/cpp/primer/operator-overloading/ - Object-Oriented Programming (OOP): /programming/cpp/primer/oop/ - Templates and Generic Programming: /programming/cpp/primer/templates/ - Namespaces: /programming/cpp/primer/namespaces/ - Pointers to Class Member: /programming/cpp/primer/pointers-to-class-member/ - Advanced: /programming/cpp/advanced/ - Error Handling: /programming/cpp/advanced/error-handling/ - Concurrency & Threading: /programming/cpp/advanced/concurrency/ - Unit Testing: /programming/cpp/advanced/unit-testing/ - Comparison: /programming/comparison/ - Kubernetes: /cloud-devops/kubernetes/ - Fleet: /cloud-devops/kubernetes/gke/fleet/ - Kustomize vs Helm: /cloud-devops/kubernetes/kustomize-vs-helm/ - API Extension: /cloud-devops/kubernetes/api-extension/ - Concept: /cloud-devops/kubernetes/kueue/concept/ - DRA: /cloud-devops/kubernetes/dra/ - Secret Manager: /cloud-devops/terraform/google-secret-manager/ - Knowledge: /network/knowledge/ - PDU: /network/knowledge/osi-model/ - curl: /network/cli/curl/ - Concurrency Concepts: /cs/concurrency-and-parallelism/concepts/ - Concurrency vs Parallelism: /cs/concurrency-and-parallelism/concurrency-vs-parallelism/ - Mutex vs Atomic: /cs/concurrency-and-parallelism/mutex-vs-atomic/ - Regular Expression: /cs/regular-expression/ - Multiplexer vs Dispatcher: /cs/multiplexer-vs-dispatcher/ - Driver and Runtime: /ai-ml/gpu/driver-and-runtime/ - Serving: /ai-ml/serving/ - Dotfiles: /dotfiles/ - Git: /dotfiles/git/ - Cheat Sheet: /dotfiles/git/cheat-sheet/ - revisions: /dotfiles/git/revisions/ - Submodule vs Worktree: /dotfiles/git/submodule-vs-worktree/ - checkout, reset -> switch, restore: /dotfiles/git/checkout-switch-restore-reset/ - rebase: /dotfiles/git/rebase/ - Branching and Merging: /dotfiles/git/branching-merging/ - Vim: /dotfiles/vim/ - Plugin: /dotfiles/vim/plugin/ - auto-pairs: /dotfiles/vim/plugin/auto-pairs/ - vim-commentary: /dotfiles/vim/plugin/vim-commentary/ - vim-easymotion: /dotfiles/vim/plugin/vim-easymotion/ - vim-surround: /dotfiles/vim/plugin/vim-surround/ - Marks: /dotfiles/vim/tips/marks/ - vimrc: /dotfiles/vim/vimrc/ - lf: /dotfiles/lf/ # Git Cheat Sheet See also: [Git Cheat Sheet](https://git-scm.com/cheat-sheet) ## Setup and Config - **`git config`**: Manage configuration options. - **Scope**: - `--system`: System-wide settings. - `--global`: User-specific settings. - `--local`: Repository-specific settings (default). - **Verb**: - `list --show-origin`: List all settings and their source file. - **Common Keys**: - `user.name`, `user.email`: Identification. - `core.editor`: Default text editor. - `init.defaultBranch`: Default branch name for `git init`. - `color.ui`: Enable colored output. - `alias.`: Create custom aliases (eg. `git config --global alias.co checkout`). See [gitconfig](https://github.com/Jssim710/dotfiles/blob/main/4-git/.gitconfig_local) - `credential.helper`: Cache or store credentials (eg. `cache` or `store`). ## Start a Working Area - **`git init`**: Initialize a new Git repository. - **`git clone []`**: Clone a repository into a new directory. - `-o `: Use `` instead of `origin` to track upstream. ## Work on the Current Change - **`git add `**: Add file contents to the index. - `-i, --interactive`: Interactive mode. - `-p, --patch`: Interactive hunk selection. - **`git restore `**: Restore working tree files. - `--staged`: Unstage a file. - `-p, --patch`: Interactive hunk selection. - **`git rm`**: Remove files from the working tree and from the index (equivalent to `rm && git add `). - `--cached`: Remove from index only (stop tracking). Useful for removing accidentally committed files (eg. `git rm --cached .env` then add `.env` to `.gitignore`). - **`git mv `**: Move or rename a file (equivalent to `mv `, `git rm `, `git add `). - **`git clean`**: Remove untracked files from the working tree. - `-n`: Dry run (show what would be deleted). - `-f`: Force (required to perform deletion). - `-d`: Remove untracked directories as well. - `-x`: Remove ignored files as well (eg. build artifacts). - `-X`: Remove *only* ignored files. ## Examine the History and State See also: [revisions]({{< relref "/dotfiles/git/revisions.md" >}}) - **`git status`**: Show the working tree status. - `-s, --short`: Show status concisely (`XY` format: `X`=staged, `Y`=WD; `A`: added, `M`: modified, `??`: untracked). - **`git diff`**: Show changes between commits, commit and working tree, etc. - Default: working tree vs. index. - `--staged`, `--cached`: index vs. `HEAD`. - ``: working tree vs. ``. - `--check`: Check for whitespace errors. - **`git difftool`**: Show changes using external diff tools. - **`git log`**: Show commit logs. - `-`: Show the last `` commits. - `-- `: Show only commits related to the specified path. - `--no-merges`: Do not show merge commits. - `--graph --oneline --all`: Visualize the history. - `-p, --patch`: Show diffs for each commit. - `--stat`: Show abbreviated stats. - `-S `: Search for commits that change the number of occurrences of a string. - **`git show []`**: Show various types of objects (commits, tags, files, etc.). - **`git reflog`**: Show the log of where `HEAD` and branch references have been. - Think of the reflog as Git’s version of shell history. ## Grow, Mark and Tweak Your Common History - **`git commit`**: Record changes to the repository. - `-m `: Commit message. - `-a, --all`: Stage all tracked files and commit. - `-p, --patch`: Interactive hunk selection. - `--amend`: Replace the last commit with a new one (can fix message or add missing changes). - `--no-edit`: Use the existing commit message without launching an editor. - **`git branch`**: Manage branches. - **No arguments**: List local branches. - ``: Create a new branch at `HEAD`. - `-d `: Delete a merged branch. - `-D `: Force delete a branch (required for unmerged branches). - `-m, --move [] `: Rename a branch. - `-f `: Force move `` to ``. - `-u []`: Set upstream for `` (defaults to current branch). - `--merged [], --no-merged []`: Filter branches by merge status relative to `` (defaults to `HEAD`). - **`git switch`**: Switch branches. - `-c []`: Create and switch to a new branch referencing `` (defaults to `HEAD`). - **`git merge `**: Join two or more development histories together. - [`--squash`]({{< relref "/dotfiles/git/branching-merging.md#squash-merge" >}}): Produce the working tree and index state as if a real merge happened, but do not actually make a commit or move the `HEAD`. - **`git mergetool`**: Resolve merge conflicts using external merge tools (eg. `vimdiff`). - **`git rebase `**: Reapply commits on top of another base tip. - `-i, --interactive`: Interactive rebase. - `git rebase `: Equivalent to `git checkout && git rebase `. - [`--onto`]({{< relref "/dotfiles/git/rebase.md" >}}) ` `: Rebase a range of commits. - **`git cherry-pick `**: Apply the changes introduced by some existing commits. - **`git reset `**: Reset current `HEAD` to the specified state. - `--hard`: Discard changes in WD and index. - `-p, --patch`: Interactive hunk selection. - **Comparison**: `git reset ` moves `HEAD` (and the current branch), while `git branch -f ` force-moves a general branch to a new commit. - **`git stash`**: Temporarily shelves changes. `push` is the default and preferred subcommand (the older `save` is deprecated). - `push` (or `git stash` alone): - `-m `: Push a new stash with a message. - `-u, --include-untracked`: Include untracked files. - `-k, --keep-index`: Stash changes but keep the index intact. - `-p, --patch`: Interactive hunk selection. - `-i, --interactive`: Interactive selection menu. - `list`: List all stashes. - `pop []`: Apply and remove from list. - `--index`: Restore the staging area (index) state. - `apply []`: Apply and keep in list. - `--index`: Restore the staging area (index) state. - `drop []`: Remove from list. - `branch []`: Create a new branch from a stash and pop it. - **`git revert `**: Revert changes introduced by some existing commits. - `-n, --no-commit`: Apply changes without creating a new commit. - `git revert ..`: Revert a range of commits (`` is exclusive, `` is inclusive). Use `^..` to include ``. - **`git tag []`**: Create a tag referencing `` (defaults to `HEAD`). - Default is a **lightweight** tag. - `-a`: Create an **annotated** tag. - `-l, --list`: List tags. - `-d `: Delete a tag. ## Collaborate - **`git remote`**: Manage set of tracked repositories. - `-v, --verbose`: Show URLs of remotes. - `add `: Add a new remote. - `rm `, `remove `: Remove a remote. - `show `: Show information about a remote. - `rename `: Rename a remote. - **`git fetch [] [][:]`**: Download objects and refs from another repository. - **`git pull [] []`**: Fetch from and integrate with another repository or a local branch. - **Equivalence**: | Command | Manual Equivalent | | :--- | :--- | | `git pull ` | `git fetch ` && `git merge /` | | `git pull --rebase ` | `git fetch ` && `git rebase /` | | `git pull :` | `git fetch :` && `git merge FETCH_HEAD` | | `git pull --rebase :` | `git fetch :` && `git rebase FETCH_HEAD` | - **`--rebase`**: Used to solve `git push` failures when the remote has new commits. It applies local commits on top of newly fetched remote commits, enabling a **fast-forward** push. - **`git push [] [][:]`**: Update remote refs along with associated objects. - **Default Behavior**: In modern Git (2.0+), running `git push` without arguments pushes the **current branch** to its corresponding upstream branch (only if the names match). - **Global Push Options**: - `-a, --all`: Push all branches. - `--mirror`: Mirror the repository (push all refs, including deletions). - `-u, --set-upstream`: Set upstream (tracking) relationship for a local branch. If the branch name is omitted, it defaults to the **currently checked-out branch** (eg. `git push -u origin`). Required for the first push of a new branch. - `--delete `: Delete a remote branch. - `--tags`: Push all local tags. - **Note**: `git fetch :` and `git push :` are symmetrical opposites. `git pull` is `git fetch` followed by a merge or rebase. - **`git ls-remote `**: List references in a remote repository. ## Worktree - **`git worktree`**: Manage multiple working trees. - `list`: List worktrees. - `add [-b] `: Add a new worktree. ## Interactive Selection (`-p, --patch`, `-i, --interactive`) Many commands (`add`, `reset`, `restore`, `stash push`, `commit`) support a "patch" mode (`-p, --patch`) or an "interactive" menu (`-i, --interactive`) to select changes at the **hunk** (part of a file) level. - `y`: stage/restore/stash this hunk. - `n`: do not stage/restore/stash this hunk. - `q`: quit; do not stage this hunk or any of the remaining ones. - `s`: split the current hunk into smaller hunks. - `e`: manually edit the current hunk.