git
33 pages
-
git amend last commit message — rewrite without a new commit
Fix the last git commit message with git commit --amend -m "New message". Works only if you have not pushed the commit yet.
-
git bisect — find the commit that introduced a bug
Use git bisect to perform a binary search through your commit history and find the exact commit that introduced a bug.
-
git cherry-pick — apply a commit from another branch
Use git cherry-pick to copy a specific commit from one branch to another without merging the whole branch.
-
git clone a specific branch
Clone a specific branch from a git repository using git clone -b branch-name. Avoids downloading all branches.
-
git delete remote branch — push delete
Delete a remote branch in git using git push origin --delete branch-name. Also covers deleting local branches and pruning stale remote refs.
-
git detached HEAD — what it means and how to fix
Fix a git detached HEAD state by creating a new branch to save your work, or switch back to an existing branch. Recover commits made while detached.
-
git diff between two branches
Compare two git branches with git diff. See all changed files, or diff a specific file between branches.
-
git discard all unstaged changes
Discard all unstaged changes in your working directory with git restore . or git checkout -- . Covers discarding a single file and staged changes.
-
git force pull / overwrite local changes — how to do it safely
Overwrite local changes with the remote branch safely using git fetch and git reset --hard origin/main. Includes a stash step if you might need your work later.
-
git push rejected — file too large
Fix git push rejected because a file exceeds the size limit. Remove the large file from history with git rm --cached or migrate it to Git LFS.
-
git line ending warning (CRLF / LF) — how to fix
Fix git line ending warnings about CRLF and LF by configuring core.autocrlf correctly for your OS, or using a .gitattributes file.
-
git merge conflict — how to resolve
Resolve a git merge conflict by editing the conflicted files, removing conflict markers, then running git add and git merge --continue.
-
git permission denied (publickey) — how to fix
Fix git permission denied (publickey) by adding your SSH key to ssh-agent and registering the public key on GitHub or GitLab. Includes macOS Keychain setup.
-
git pull --rebase vs --merge — which to use
Understand the difference between git pull --rebase and git pull --merge. Use rebase for a linear history, merge for explicit merge commits.
-
git push rejected (non-fast-forward) — how to fix
Fix git push rejected non-fast-forward by running git pull --rebase before pushing. The remote has commits your local branch does not have.
-
git rebase --abort — cancel a rebase in progress
Cancel an in-progress git rebase and restore your branch to its pre-rebase state with git rebase --abort.
-
git recover deleted branch — using reflog
Recover a deleted git branch by finding its last commit in git reflog and recreating the branch with git checkout -b.
-
git remote change URL — switch origin or add new remote
Change a git remote URL with git remote set-url. Switch between HTTPS and SSH, or update after a repository was renamed or moved.
-
git remove all untracked files and directories
Remove untracked files from your working directory using git clean. Use -n for a dry run first to see what would be deleted.
-
git rename a branch (local and remote)
Rename a git branch locally with git branch -m, then update the remote by pushing the new name and deleting the old one.
-
git reset --soft vs --mixed vs --hard — the difference
Understand the difference between git reset --soft, --mixed (default), and --hard. Which one keeps your changes and which one discards them.
-
git revert merge commit — how to undo a merge safely
Undo a merge commit without rewriting history using git revert -m 1 <merge-commit>. Includes how to find the merge hash and choose the correct parent.
-
git convert shallow clone to full history
Convert a shallow git clone (--depth 1) to a full clone with complete history using git fetch --unshallow.
-
git show a file at a specific commit
View or restore a file from any past git commit using git show or git checkout. No need to switch branches.
-
git squash commits — combine commits before merging
Squash multiple git commits into one using interactive rebase (git rebase -i). Clean up your commit history before opening a pull request.
-
git SSL certificate problem — how to fix
Fix git SSL certificate problem: unable to get local issuer certificate by configuring the correct CA bundle or temporarily disabling SSL verification.
-
git stash drop — remove a specific stash
Drop a specific git stash entry with git stash drop stash@{n}, or clear all stashes at once with git stash clear.
-
git submodule update — initialize and update all submodules
Initialize and update all git submodules recursively with git submodule update --init --recursive. Fix missing submodule directories after cloning.
-
git tag a specific commit — create and push tags
Tag a specific git commit with git tag and push it to the remote. Covers annotated tags, listing tags, and deleting tags.
-
git undo last commit — keep or discard changes
Undo the last git commit without losing your work using git reset --soft HEAD~1. Covers all three modes: soft, mixed, and hard reset.
-
git stop tracking a file — remove from git without deleting
Stop tracking a file that is already committed in git using git rm --cached, then add it to .gitignore so it stays ignored going forward.
-
git worktree — work on multiple branches simultaneously
Use git worktree to check out multiple branches at once in separate directories. No stashing or switching required.