⚡ OPENDEV HUB V1.0⚡ API STATUS: 100% OPERATIONAL⚡ CLIENT ENGINE: LOADED & CACHED⚡ TRENDING TECH: TAILWIND V4, NEXT.JS 16, RUST, GO⚡ ZERO AUTH REQUIRED
OPENDEVHUB

Command Palette

Search for a command to run...

GITHUB CHEATSHEET

GITHUB UNIVERSAL CHEATSHEET & TROUBLESHOOTING

A definitive, searchable index of core Git operations and solutions to common workflow issues. Filter by category, search errors, and copy clean snippets instantly.

Git Basics & Setup12 ENTRIES

git initGit Basics & Setup

Initialize a local Git repository in the current directory.

SYNTAX:
git init [directory-name]
EXAMPLE USAGE:
git init my-awesome-app
COMMON PITFALL:

Running git init inside a folder that is already inside an existing Git repository, creating nested repository states.

git cloneGit Basics & Setup

Clone a remote repository to your local system.

SYNTAX:
git clone <url> [directory-name]
EXAMPLE USAGE:
git clone https://github.com/vercel/next.js.git
COMMON PITFALL:

Forgetting to cd into the newly cloned directory after cloning, and running commands in the parent folder.

git configGit Basics & Setup

Set repository or global configuration values like username and email.

SYNTAX:
git config --global user.name "Name"
git config --global user.email "email@domain.com"
EXAMPLE USAGE:
git config --global user.name "Jane Doe"
git config --global user.email "jane@example.com"
COMMON PITFALL:

Setting configurations locally in a directory not initialized as a git repository, or typing typos in emails leading to untracked GitHub stats.

git statusGit Basics & Setup

Show the status of files in the working directory and staging area (tracked/untracked/modified).

SYNTAX:
git status
EXAMPLE USAGE:
git status
COMMON PITFALL:

Relying on status blindly before committing without double checking the actual file diffs.

git addGit Basics & Setup

Add file changes in your working directory to the staging area.

SYNTAX:
git add <file-or-directory>
# Stage all changes:
git add .
EXAMPLE USAGE:
git add src/components/Header.tsx
git add .
COMMON PITFALL:

Staging secret credential files, environment files (.env), or node_modules accidentally using 'git add .'.

git commitGit Basics & Setup

Record staged snapshots in version history.

SYNTAX:
git commit -m "<message>"
EXAMPLE USAGE:
git commit -m "feat: implement client-side regex tester"
COMMON PITFALL:

Writing generic commit messages like 'fix' or 'update' which make history hard to search, or committing without staging first.

git logGit Basics & Setup

Show commit logs/history of the active branch.

SYNTAX:
git log --oneline --graph --decorate
EXAMPLE USAGE:
git log --oneline -n 10
COMMON PITFALL:

Forgetting that git log shows history page-by-page and getting stuck inside the command pager (press 'q' to exit).

git diffGit Basics & Setup

Show changes between commits, commit and working tree, or staged and unstaged states.

SYNTAX:
git diff [commit-hash]
# Show staged differences:
git diff --staged
EXAMPLE USAGE:
git diff HEAD~1
git diff --staged
COMMON PITFALL:

Running git diff without staging parameters and wondering why staged changes are not showing up.

git showGit Basics & Setup

Show various types of objects (commits, tags, files) with their content/diff metadata.

SYNTAX:
git show <commit-hash>:[filepath]
EXAMPLE USAGE:
git show a1b2c3d:src/App.tsx
COMMON PITFALL:

Running git show without a commit hash when you want to view a past commit, which default shows only the latest commit.

git rmGit Basics & Setup

Remove files from the working tree and index (stage).

SYNTAX:
git rm <filepath>
# Untrack file but keep it locally:
git rm --cached <filepath>
EXAMPLE USAGE:
git rm --cached .env
COMMON PITFALL:

Running 'git rm <file>' without '--cached' when you want to keep the local copy; this will permanently delete the local file.

git mvGit Basics & Setup

Move or rename a file, a directory, or a symlink.

SYNTAX:
git mv <source> <destination>
EXAMPLE USAGE:
git mv old-name.js new-name.js
COMMON PITFALL:

Renaming files directly using your OS explorer; git treats it as deleted and untracked. Use git mv to preserve file history.

git helpGit Basics & Setup

Display help information/manual pages for Git commands.

SYNTAX:
git help <command>
EXAMPLE USAGE:
git help rebase
COMMON PITFALL:

Searching online manuals when git help runs the complete offline documentation instantly in your local browser.

Branching & Merging9 ENTRIES

git checkoutBranching & Merging

Switch branches or restore working tree files.

SYNTAX:
git checkout <branch-name>
# Switch to past commit:
git checkout <commit-hash>
EXAMPLE USAGE:
git checkout feature/navbar
COMMON PITFALL:

Switching branches with uncommitted modifications, which can cause conflict blockages.

git switchBranching & Merging

Switch branches safely (a cleaner alternative to git checkout for branch navigation).

SYNTAX:
git switch <branch-name>
# Create and switch:
git switch -c <branch-name>
EXAMPLE USAGE:
git switch -c feat/analytics
COMMON PITFALL:

Forgetting that git switch only works for branches, not for viewing specific commits or file resets (use restore for files).

git restoreBranching & Merging

Restore working tree files from index or specific commits.

SYNTAX:
git restore <filepath>
# Unstage file changes:
git restore --staged <filepath>
EXAMPLE USAGE:
git restore --staged package-lock.json
COMMON PITFALL:

Discarding modifications to working files; restored modifications cannot be recovered.

git branchBranching & Merging

List, create, or delete branches.

SYNTAX:
git branch # list local
git branch -a # list local + remote
git branch -d <branch-name> # delete merged branch
git branch -D <branch-name> # force delete branch
EXAMPLE USAGE:
git branch -D old-experiment
COMMON PITFALL:

Trying to delete the branch you are currently on. Switch to another branch first.

git mergeBranching & Merging

Merge target branch history into the active head branch.

SYNTAX:
git merge <branch-name>
EXAMPLE USAGE:
git merge main
COMMON PITFALL:

Merging without running git pull first, leading to conflicts on outdated commits.

git rebaseBranching & Merging

Reapply commits on top of another base tip. Keeps a clean linear history.

SYNTAX:
git rebase <base-branch>
EXAMPLE USAGE:
git rebase main
COMMON PITFALL:

Rebasing commits that have already been pushed to public/shared branches, rewriting history for other developers.

git cherry-pickBranching & Merging

Apply the changes introduced by some existing commits onto the current branch.

SYNTAX:
git cherry-pick <commit-hash>
EXAMPLE USAGE:
git cherry-pick a1c3f9e
COMMON PITFALL:

Cherry-picking commits without realizing they depend on changes introduced in prior commits, causing build failures.

git merge-baseBranching & Merging

Find as good common ancestors as possible for a merge.

SYNTAX:
git merge-base <branch-1> <branch-2>
EXAMPLE USAGE:
git merge-base feature main
COMMON PITFALL:

Using manual diff comparisons when merge-base identifies exactly where the branch diverged.

git shortlogBranching & Merging

Summarize git log output, grouping commits by author.

SYNTAX:
git shortlog -s -n
EXAMPLE USAGE:
git shortlog -s -n
COMMON PITFALL:

Running shortlog without tags in huge repositories, resulting in spamming logs for thousands of commits.

Remotes & Collaboration9 ENTRIES

git remoteRemotes & Collaboration

Manage set of tracked repositories (remotes).

SYNTAX:
git remote -v
git remote add <name> <url>
git remote remove <name>
EXAMPLE USAGE:
git remote add upstream https://github.com/org/repo.git
COMMON PITFALL:

Adding duplicate remote names or typos in URLs, making it impossible to pull/push.

git fetchRemotes & Collaboration

Download objects and refs from another repository. Does not modify local files.

SYNTAX:
git fetch <remote>
EXAMPLE USAGE:
git fetch origin
COMMON PITFALL:

Thinking git fetch updates your active working code. You must merge or rebase after fetching to sync.

git pullRemotes & Collaboration

Fetch from and integrate with another repository or local branch.

SYNTAX:
git pull <remote> <branch>
EXAMPLE USAGE:
git pull origin main
COMMON PITFALL:

Running git pull when you have dirty uncommitted local modifications, causing automatic merging to fail.

git pushRemotes & Collaboration

Update remote refs along with associated objects.

SYNTAX:
git push <remote> <branch>
# Set upstream tracking branch:
git push -u origin <branch>
EXAMPLE USAGE:
git push -u origin feature-x
COMMON PITFALL:

Using push --force blindly on master/main branches, destroying other team members' code snapshots.

git remote pruneRemotes & Collaboration

Delete stale tracking branches under <name> that no longer exist on the remote.

SYNTAX:
git remote prune <remote-name>
EXAMPLE USAGE:
git remote prune origin
COMMON PITFALL:

Expecting local physical branches to be deleted. It only cleans obsolete remote-tracking markers (e.g. origin/feature-x).

git remote showRemotes & Collaboration

Give information about a specific remote repository.

SYNTAX:
git remote show <remote-name>
EXAMPLE USAGE:
git remote show origin
COMMON PITFALL:

Running this offline; it requires active remote network communication to check branch sync states.

git clone --mirrorRemotes & Collaboration

Clone repository containing all branch references, tags, and settings as a full mirror.

SYNTAX:
git clone --mirror <url>
EXAMPLE USAGE:
git clone --mirror https://github.com/user/project.git
COMMON PITFALL:

Cloning a mirror expecting a normal working tree; it contains only raw .git databases (bare repository).

git submoduleRemotes & Collaboration

Initialize, update, or inspect nested submodules inside a Git repository.

SYNTAX:
git submodule add <url> <path>
git submodule update --init --recursive
EXAMPLE USAGE:
git submodule update --init --recursive
COMMON PITFALL:

Cloning a project containing submodules without running 'submodule update --init', leaving submodules empty.

git request-pullRemotes & Collaboration

Generate a summary of pending changes to ask upstream maintainers to pull.

SYNTAX:
git request-pull <start-commit> <url> [end-commit]
EXAMPLE USAGE:
git request-pull v1.0 https://github.com/my/repo main
COMMON PITFALL:

Specifying wrong range boundaries, causing unnecessary or unrelated changes to be requested.

Undoing & Fixing Errors8 ENTRIES

git reset --softUndoing & Fixing Errors

Undo the last commit(s), moving HEAD back, but keeping all changes staged in the index.

SYNTAX:
git reset --soft HEAD~<number-of-commits>
EXAMPLE USAGE:
git reset --soft HEAD~1
COMMON PITFALL:

Assuming changes are deleted. This command preserves all modified code in your staged index.

git reset --mixedUndoing & Fixing Errors

Undo commits and unstage changes, leaving files modified in working directory. This is the default reset mode.

SYNTAX:
git reset --mixed HEAD~1
EXAMPLE USAGE:
git reset HEAD~1
COMMON PITFALL:

Running this when you wanted to keep modifications staged. You will have to re-add changes to the stage.

git reset --hardUndoing & Fixing Errors

Discard all uncommitted changes and revert to a specific commit. Warning: destructive operation!

SYNTAX:
git reset --hard <commit-hash>
EXAMPLE USAGE:
git reset --hard HEAD~1
COMMON PITFALL:

Executing reset --hard when you have valuable uncommitted modifications; they will be permanently lost.

git revertUndoing & Fixing Errors

Create a new commit that undoes the effects of previous commits without rewriting history.

SYNTAX:
git revert <commit-hash>
EXAMPLE USAGE:
git revert 8b3c9e1
COMMON PITFALL:

Reverting a commit that was already reverted, causing confusing logical code loops in history.

git reflogUndoing & Fixing Errors

Show a record of all commits, branch switches, resets, and merges. Best tool to recover 'lost' commits.

SYNTAX:
git reflog
EXAMPLE USAGE:
git reflog
COMMON PITFALL:

Assuming deleted branches or hard resets are unrecoverable without checking reflog first.

git cleanUndoing & Fixing Errors

Remove untracked files and directories from the working tree.

SYNTAX:
git clean -fd
# Dry run check first:
git clean -nfd
EXAMPLE USAGE:
git clean -fd
COMMON PITFALL:

Running clean without double-checking the files list via dry-run (-n), which permanently deletes local configuration files.

git commit --amendUndoing & Fixing Errors

Replace the tip commit of the current branch with a new commit, allowing changes or rewrites to message.

SYNTAX:
git commit --amend -m "<new-message>"
EXAMPLE USAGE:
git commit --amend -m "docs: fix header typo"
COMMON PITFALL:

Amending a commit that has already been pushed to a shared remote, which will require force-pushing.

git checkout --Undoing & Fixing Errors

Discard local changes in the working directory (older equivalent to git restore).

SYNTAX:
git checkout -- <filepath>
EXAMPLE USAGE:
git checkout -- src/styles.css
COMMON PITFALL:

Conflating this branch-switching command syntax, which is why git restore is preferred in modern Git.

Stashing7 ENTRIES

git stashStashing

Temporarily save (stash) changes in your dirty working directory so you can work on something else.

SYNTAX:
git stash save "<message>"
# Save with untracked files:
git stash -u
EXAMPLE USAGE:
git stash save "layout edits WIP" -u
COMMON PITFALL:

Stashing without keeping track of what was modified, then accumulating 30 stashes and forgetting which is which.

git stash listStashing

List stashed state changes.

SYNTAX:
git stash list
EXAMPLE USAGE:
git stash list
COMMON PITFALL:

Stashing changes and then forgetting about them, resulting in merge issues weeks later.

git stash popStashing

Remove the single most recently stashed state from the stash list and apply it to active branch.

SYNTAX:
git stash pop [stash-index]
EXAMPLE USAGE:
git stash pop stash@{0}
COMMON PITFALL:

Popping a stash on a branch different from where you created it, causing messy merge conflicts.

git stash applyStashing

Apply stashed changes to active branch, but do not delete the stash from the stashing list.

SYNTAX:
git stash apply [stash-index]
EXAMPLE USAGE:
git stash apply stash@{1}
COMMON PITFALL:

Applying stash multiple times by mistake, creating duplicated merge conflict sections.

git stash dropStashing

Remove a single stashed state from the stash list.

SYNTAX:
git stash drop <stash-index>
EXAMPLE USAGE:
git stash drop stash@{2}
COMMON PITFALL:

Dropping the wrong stash index because the indices shift after popping or dropping other items.

git stash clearStashing

Remove all stashed states. Warning: irreversible action!

SYNTAX:
git stash clear
EXAMPLE USAGE:
git stash clear
COMMON PITFALL:

Clearing the entire stash pool when you wanted to delete a single stash index, resulting in lost stashed code.

git stash showStashing

Show the changes recorded in the stash as a diff.

SYNTAX:
git stash show -p [stash-index]
EXAMPLE USAGE:
git stash show -p stash@{0}
COMMON PITFALL:

Running stash show without '-p' when you want to view the actual file diffs (defaults to file stats summary).

Tagging & Releases5 ENTRIES

git tagTagging & Releases

List tags in alphabetical order, or look up specific tags.

SYNTAX:
git tag
git tag -l "v1.2.*"
EXAMPLE USAGE:
git tag -l "v2.0.*"
COMMON PITFALL:

Forgetting that git tag only lists local tags unless updated via git fetch.

git tag -aTagging & Releases

Create an annotated tag containing tagger metadata, date, and messages, GPG signed if specified.

SYNTAX:
git tag -a <tag-name> -m "<tag-message>"
EXAMPLE USAGE:
git tag -a v1.0.0 -m "Release v1.0.0 stable release version"
COMMON PITFALL:

Creating lightweight tags (without -a) for public releases, which omit tagger identification details.

git tag -dTagging & Releases

Delete a local tag.

SYNTAX:
git tag -d <tag-name>
EXAMPLE USAGE:
git tag -d v1.0.0-rc1
COMMON PITFALL:

Deleting a local tag thinking it automatically deletes the tag on GitHub. Remote tags must be purged separately.

git push origin --tagsTagging & Releases

Push all local tags that are not yet on the remote server.

SYNTAX:
git push <remote> --tags
EXAMPLE USAGE:
git push origin --tags
COMMON PITFALL:

Running 'git push' without '--tags' when publishing releases; normal push commands do not transfer tags.

git push origin :refs/tags/Tagging & Releases

Delete a tag on the remote repository.

SYNTAX:
git push <remote-name> --delete <tag-name>
# Older syntax:
git push <remote-name> :refs/tags/<tag-name>
EXAMPLE USAGE:
git push origin --delete v1.0.0-beta
COMMON PITFALL:

Leaving a broken tag on remote repositories which causes conflict failures for other developers during fetch.

Advanced Utilities & Plumbing11 ENTRIES

git rebase -iAdvanced Utilities & Plumbing

Start an interactive rebase session to edit, squash, reword, or drop commits in history.

SYNTAX:
git rebase -i HEAD~<number-of-commits>
EXAMPLE USAGE:
git rebase -i HEAD~5
COMMON PITFALL:

Closing the text editor without realizing it initiates the rebase, or deleting commits accidentally from the pick list.

git worktreeAdvanced Utilities & Plumbing

Manage multiple working trees attached to the same repository. Work on multiple branches in different folders simultaneously.

SYNTAX:
git worktree add <path> <branch>
git worktree list
git worktree remove <path>
EXAMPLE USAGE:
git worktree add ../debug-build hotfix/auth
COMMON PITFALL:

Modifying files inside a worktree thinking it is a separate repository, and forgetting to prune removed worktrees.

git bisectAdvanced Utilities & Plumbing

Use binary search to find the commit that introduced a bug.

SYNTAX:
git bisect start
git bisect bad # Current version has the bug
git bisect good <commit-hash> # Last known working version
# Type 'git bisect good' or 'git bisect bad' iteratively, then:
git bisect reset
EXAMPLE USAGE:
git bisect start
git bisect bad
git bisect good v1.0.0
COMMON PITFALL:

Forgetting to run 'git bisect reset' after finding the bug, leaving the repository in a detached HEAD bisect state.

git blameAdvanced Utilities & Plumbing

Show what revision and author last modified each line of a file.

SYNTAX:
git blame <filepath>
EXAMPLE USAGE:
git blame src/components/Header.tsx
COMMON PITFALL:

Blaming files that have been auto-formatted, which shows the formatter author instead of the logic author (use --ignore-revs-file if needed).

git archiveAdvanced Utilities & Plumbing

Create a zip or tar archive of the files in a repository from specific branches or commits.

SYNTAX:
git archive --format=<zip|tar> --output=<filename> <branch-name>
EXAMPLE USAGE:
git archive --format=zip --output=v1-source.zip main
COMMON PITFALL:

Archiving repositories and expecting the .git history directory to be included; it only packs working directory code.

git gcAdvanced Utilities & Plumbing

Run garbage collection to optimize database size, clean up unreachable commits, and compress history.

SYNTAX:
git gc --prune=now
EXAMPLE USAGE:
git gc --prune=now
COMMON PITFALL:

Pruning reflog commits that you might still want to restore. Use with caution!

git fsckAdvanced Utilities & Plumbing

Verify the connectivity and validity of objects in the database, checking for corrupted commits.

SYNTAX:
git fsck --full
EXAMPLE USAGE:
git fsck --full
COMMON PITFALL:

Running fsck and deleting loose objects without back-ups if corruption occurred.

git format-patchAdvanced Utilities & Plumbing

Prepare commits for email submission, generating a series of .patch files.

SYNTAX:
git format-patch <start-commit-hash>..HEAD
EXAMPLE USAGE:
git format-patch v1.0.0..main
COMMON PITFALL:

Creating format-patches in a folder where you have local uncommitted changes, making organization messy.

git amAdvanced Utilities & Plumbing

Apply a series of patches from a mailbox/local patch files.

SYNTAX:
git am < <patch-file>
EXAMPLE USAGE:
git am 0001-fix-layout-bug.patch
COMMON PITFALL:

Applying patches generated from an incompatible branch state, leading to patch conflict failures.

git bundleAdvanced Utilities & Plumbing

Package objects and references in an offline file. Useful for sharing code without remote servers.

SYNTAX:
git bundle create <filename> <branch-name>
# Clone from a bundle:
git clone <filename> -b <branch>
EXAMPLE USAGE:
git bundle create backup.bundle main
COMMON PITFALL:

Forgetting to specify references (branches/tags) when packaging, resulting in an empty bundle file.

git describeAdvanced Utilities & Plumbing

Find the most recent tag reachable from a commit, suffixing it with commit counts and hashes.

SYNTAX:
git describe --tags --always
EXAMPLE USAGE:
git describe --tags --always
COMMON PITFALL:

Assuming it works in a repository without any tags, which will fall back to returning only the commit hash.

Git Disasters & Solutions14 ENTRIES

Fix: Committed to main directlyGit Disasters & Solutions

You accidentally committed code directly to the 'main' branch instead of a dedicated feature branch.

SYNTAX:
# 1. Create a new branch pointing to current changes:
git branch feat/your-feature-name
# 2. Reset local main back one commit (or more):
git reset --hard HEAD~1
# 3. Switch to your feature branch:
git checkout feat/your-feature-name
EXAMPLE USAGE:
git branch feat/search-bar
git reset --hard HEAD~1
git checkout feat/search-bar
COMMON PITFALL:

Performing this action if you already pushed main to GitHub. You will have to coordinate with your team to force-push.

Fix: Undo last commitGit Disasters & Solutions

You made a commit but immediately realized you made a typo or forgot to include a file, and want to redo it.

SYNTAX:
# Undo commit, keep files modified and staged:
git reset --soft HEAD~1
# Undo commit, keep files modified but unstaged:
git reset HEAD~1
EXAMPLE USAGE:
git reset --soft HEAD~1
COMMON PITFALL:

Using 'git reset --hard HEAD~1' instead, which will completely delete the changes you just made.

Fix: Recover hard resetGit Disasters & Solutions

You accidentally ran 'git reset --hard' and lost all your uncommitted or committed work.

SYNTAX:
# 1. Run reflog to find the commit hash before the reset:
git reflog
# 2. Revert HEAD to that commit hash:
git reset --hard <commit-hash>
EXAMPLE USAGE:
git reflog
# Output showing: HEAD@{1}: reset: moving to HEAD~1
# HEAD@{2}: commit: feat: added sidebar
git reset --hard a2f3c9e
COMMON PITFALL:

Running 'git clean -fd' or closing the workspace before fetching the hash from the log, or thinking uncommitted changes can be recovered this way (reflog only recovers committed changes).

Fix: Purge sensitive dataGit Disasters & Solutions

You accidentally committed a file containing API keys, passwords, or secrets, and need to scrub it from all branch histories.

SYNTAX:
# Remove the file from all commits and rewrite history:
git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch <filename>" \
  --prune-empty --tag-name-filter cat -- --all
# Note: Force pushing is required afterwards:
git push origin --force --all
EXAMPLE USAGE:
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch .env" --prune-empty --tag-name-filter cat -- --all
COMMON PITFALL:

Assuming simple 'git rm file' deletes it from history. The keys will still be accessible in past commits unless history is rewritten.

Fix: Case-sensitive file renameGit Disasters & Solutions

You changed a filename's casing (e.g., header.tsx to Header.tsx), but Git doesn't detect the modification due to default config.

SYNTAX:
# Force rename via Git:
git mv <old-name> <new-name>
# Alternatively, disable core ignorecase:
git config core.ignorecase false
EXAMPLE USAGE:
git mv src/components/header.tsx src/components/Header.tsx
COMMON PITFALL:

Renaming the file directly in your OS Explorer or VS Code sidebar. Git will show duplicate untracked/deleted files.

Fix: Rename branchGit Disasters & Solutions

You need to rename your active local branch and update the remote tracking branch accordingly.

SYNTAX:
# 1. Rename active branch locally:
git branch -m <new-name>
# 2. Push the new branch and set remote upstream:
git push origin -u <new-name>
# 3. Delete the old branch on the remote server:
git push origin --delete <old-name>
EXAMPLE USAGE:
git branch -m feat/search-ui
git push origin -u feat/search-ui
git push origin --delete feat/srch-ui
COMMON PITFALL:

Renaming a branch other developers are actively basing their pull requests on, breaking their target remotes.

Fix: Discard local changesGit Disasters & Solutions

You want to completely erase all local modifications (tracked and untracked) to start over from fresh pull state.

SYNTAX:
# 1. Reset all tracked files to current commit:
git reset --hard HEAD
# 2. Remove all untracked files and directories:
git clean -fd
EXAMPLE USAGE:
git reset --hard HEAD && git clean -fd
COMMON PITFALL:

Running 'git clean -fdx' if you want to keep files in your gitignore, like local .env files or configuration parameters.

Fix: Wrong commit authorGit Disasters & Solutions

You committed code but realized it has the wrong git author email or name.

SYNTAX:
# Update only the last commit:
git commit --amend --author="Name <email@example.com>"
EXAMPLE USAGE:
git commit --amend --author="John Doe <john@doe.com>"
COMMON PITFALL:

Amending a commit that you have already pushed to a shared remote, which requires force-pushing.

Fix: Resolve merge conflictsGit Disasters & Solutions

Your branch conflicts with another branch and Git halts the merge, inserting conflict markers.

SYNTAX:
# 1. Run status to list conflicting files:
git status
# 2. Open files, resolve markers (<<<<<<<, =======, >>>>>>>), then stage:
git add <resolved-file>
# 3. Complete the merge transaction:
git commit -m "merge: resolved conflicts with origin/main"
EXAMPLE USAGE:
git status
# resolve conflicts in files...
git add src/components/Header.tsx
git commit -m "merge: resolved conflicts"
COMMON PITFALL:

Running git commit before resolving all files, or committing code with raw conflict symbols (<<<<<<<) still left in files.

Fix: Undo a merge commitGit Disasters & Solutions

You merged a branch but realized it broke the project, and you want to completely rollback the merge commit.

SYNTAX:
# Revert a merge commit, specifying the mainline parent index (usually 1):
git revert -m 1 <merge-commit-hash>
EXAMPLE USAGE:
git revert -m 1 3c8e4a2
COMMON PITFALL:

Using normal git revert without the -m option, which causes git to throw an error since merge commits have multiple parents.

Fix: Push rejected (non-fast-forward)Git Disasters & Solutions

Your push is rejected because the remote contains commits you don't have locally.

SYNTAX:
# 1. Fetch remote updates and rebase your local commits on top:
git pull --rebase origin <branch-name>
# 2. Resolve conflicts if any, and continue rebase:
git rebase --continue
# 3. Safely push modifications:
git push origin <branch-name>
EXAMPLE USAGE:
git pull --rebase origin main && git push origin main
COMMON PITFALL:

Using 'git push --force' without checking remote differences, which will overwrite other developers' work permanently.

Fix: Recover deleted branchGit Disasters & Solutions

You deleted a branch locally using git branch -D and now want to restore it.

SYNTAX:
# 1. Find the tip commit hash of the deleted branch in reflog:
git reflog
# 2. Re-create the branch from that commit hash:
git branch <branch-name> <commit-hash>
EXAMPLE USAGE:
git reflog
# HEAD@{3}: checkout: moving from feature-auth to main
# HEAD@{4}: commit: feat: added bcrypt auth
git branch feature-auth a1c2b3d
COMMON PITFALL:

Thinking deleted branches are gone forever, or running garbage collection (git gc) which purges dangling commit objects.

Fix: Index lock error (index.lock)Git Disasters & Solutions

Git commands fail with 'Another git process seems to be running in this repository' error because of a stale lock file.

SYNTAX:
# Remove the stale index lock file manually:
rm -f .git/index.lock
EXAMPLE USAGE:
rm -f .git/index.lock
COMMON PITFALL:

Deleting files under the refs directory or deleting index itself, which corrupts version staging tables.

Fix: File too large (over 100MB)Git Disasters & Solutions

GitHub rejects your push because you committed a file exceeding the 100MB limit.

SYNTAX:
# 1. Remove large file from active index:
git rm --cached <path-to-large-file>
# 2. Rewrite history to remove files from past commits:
git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch <path-to-large-file>" \
  --prune-empty --tag-name-filter cat -- --all
# 3. Push history clean:
git push origin main
EXAMPLE USAGE:
git rm --cached data/large_dataset.zip && git filter-branch --force --index-filter "git rm --cached --ignore-unmatch data/large_dataset.zip" --prune-empty --tag-name-filter cat -- --all
COMMON PITFALL:

Deleting the file locally and committing the delete; the file will still exist in historical commit objects, blocking pushes.