Intermediate Level
50 questions covering Part 2: Advanced Branching, Rebasing & Merge Conflict Mastery.
How do you execute an Interactive Rebase (
git rebase -i)?[ bash ] git rebase -i HEAD~4Opens an editor with options:
pick: Use commit as-is.reword: Change commit message.edit: Pause to amend files.squash: Meld commit into previous commit and combine messages.fixup: Meld commit into previous commit and discard message.drop: Delete the commit.
How do you resolve a complex Git Merge Conflict?
- Git halts on conflict, marking files with conflict markers (
<<<<<<< HEAD,=======,>>>>>>>). - Inspect conflicting blocks; manually edit code to reconcile desired logic.
- Stage resolved files:
git add <file>. - Complete the operation:
git merge --continueorgit rebase --continue.
- Git halts on conflict, marking files with conflict markers (
What is
git rerere(Reuse Recorded Resolution)?Automatically records how you resolved a merge conflict. When the exact same merge conflict occurs in the future (during rebases or branch updates), Git resolves it automatically using the recorded solution. Enable via
git config --global rerere.enabled true.What is Trunk-Based Development vs GitFlow?
- Trunk-Based: Developers merge small, frequent commits into a single shared branch (
main) multiple times a day, enabling CI/CD. - GitFlow: Heavy model with long-lived branches (
develop,feature,release,hotfix,master) that delays integration and causes merge hell.
- Trunk-Based: Developers merge small, frequent commits into a single shared branch (
What is
git push --force-with-leasevs--force?--force: Unconditionally overwrites the remote branch, potentially destroying teammates' commits pushed in the interim.--force-with-lease: Rejects the push if the remote branch reference has changed since your last fetch, protecting against overwriting un-fetched remote work.
What is
git gc(Garbage Collection)?Optimizes repository storage by packing loose objects into compressed packfiles (
.pack), removing orphaned unreachable objects, and pruning old reflog entries.What is
git fsck?File System Consistency Check that verifies the cryptographic connectivity and integrity of objects in the Git database, identifying dangling blobs and commits.
What is
git-filter-repo(BFG Repo-Cleaner)?High-performance tools for permanently stripping sensitive files (leaked passwords, large binaries) from entire Git commit history across all branches and tags.
What is a Git Hook (
pre-commit,commit-msg,pre-push)?Scripts placed in
.git/hooks/that execute automatically at key lifecycle points (e.g.,pre-commitruns linters and secret scanners before creating a commit).What is Git Signed Commits (GPG / SSH)?
Signing commits with a private cryptographic key (
git commit -S -m "msg"). GitHub displays a "Verified" badge, proving commit authenticity and author identity.What is
git rebase --onto?Replants a branch topic that was branched off an old feature onto a completely different base branch:
git rebase --onto main old_feature client_branch.What is
git cherry-pick -n(No Commit)?Applies the diff from the target commit to your working directory and staging area without creating a commit, allowing you to batch multiple cherry-picks.
What is
git merge --squash?Combines all commits from a feature branch into a single set of staged changes on the target branch without creating a merge commit, ready to be committed as one clean commit.
What is
git diffThree-Dot (...) vs Two-Dot (..)?git diff branchA..branchB: Shows direct diff between the tips of branchA and branchB.git diff branchA...branchB: Shows the diff introduced on branchB since its common merge-base ancestor with branchA.
What is
git logThree-Dot (...) vs Two-Dot (..)?git log master..feature: Shows commits present onfeaturebut missing frommaster.git log master...feature: Shows commits present on either branch, excluding commits common to both (symmetric difference).
What is
git notes?Attaches arbitrary metadata, code review comments, or build URLs to existing commits without modifying commit SHAs.
What is
git worktree?Allows checking out and developing on multiple branches simultaneously in separate directory folders on disk from a single cloned repository.
What is
git submodule update --init --recursive?Initializes, clones, and checks out all nested submodules declared in
.gitmodules.What is
git sparse-checkout?Configures the working directory to populate only specified subfolders of a large monorepo, leaving all other files unmaterialized on disk.
What is
git replace?Creates replacement refs allowing you to graft historical repositories or alter commit history view without modifying underlying commit objects.
What is
git shallow clone(--depth=N)?Clones only the most recent $N$ commits, creating a truncated history to optimize pipeline checkout speeds.
What is
git blobless clone(--filter=blob:none)?Clones all commit trees and history while downloading file blobs on-demand only when checking out files, saving gigabytes in massive monorepos.
What is
git treeless clone(--filter=tree:0)?Clones only commit objects, downloading trees and blobs on-demand during checkout.
What is
git commit --fixupandgit rebase --autosquash?git commit --fixup <sha>: Creates a fixup commit targeting a prior commit.git rebase -i --autosquash: Automatically reorders and marks all fixup commits to squash into their target parents automatically.
What is
git checkout -b <branch> --track <remote>/<branch>?Creates a new local branch and configures upstream remote tracking in a single command.
What is
git branch -Dvs-d?-d(Safe): Deletes branch only if it has already been fully merged into upstream.-D(Force): Forcibly deletes branch regardless of merge status.
What is
git remote prune origin?Cleans up stale local tracking branches under
refs/remotes/origin/that have been deleted on the remote GitHub server.What is
git branch --mergedvs--no-merged?--merged: Lists local branches that have been merged intoHEAD(safe to delete).--no-merged: Lists branches containing unmerged commits.
What is
git push origin :<branch>?Legacy syntax to delete a remote branch on the server (equivalent to
git push origin --delete <branch>).What is
git push origin --tags?Pushes all local tags to the remote repository.
What is
git tag -d <tag>andgit push origin :refs/tags/<tag>?Deletes a tag locally and removes it from the remote repository.
What is
git config --global pull.rebase true?Configures
git pullto execute a rebase instead of creating a merge commit, maintaining a linear commit history.What is
git config --global init.defaultBranch main?Sets
mainas the default branch name for newly initialized repositories.What is
git config --global core.autocrlf?true(Windows): Converts LF to CRLF on checkout, converts CRLF to LF on commit.input(Linux/macOS): Converts CRLF to LF on commit.
What is
.gitattributesandeol=lf?Declares repository-wide line ending and binary file handling rules committed to Git to enforce consistent LF endings across operating systems.
What is
.gitattributesdiff=nodiff?Marks generated files (minified JS, lockfiles) so
git diffdoes not clutter reviews with massive text diffs.What is
git stash branch <branch>?Creates and checks out a new branch starting from the commit where the stash was created, then applies and drops the stash.
What is
git stash push -m "message"?Saves a stash with a descriptive label for easy identification in
git stash list.What is
git stash show -p?Displays the full unified diff of changes stored inside a stash.
What is
git stash drop stash@{N}?Permanently deletes a specific stash entry from the stack.
What is
git stash clear?Deletes all stashes in the repository.
What is
git bisect run <script.sh>?Automates bisecting by executing a script that tests code and returns exit code 0 (good) or non-zero (bad), finding the broken commit in seconds.
What is
git bisect reset?Terminates the bisect session and returns the working directory to the original branch
HEAD.What is
git cherry-pick --abort?Cancels an in-progress cherry-pick operation and restores the repository state prior to the command.
What is
git rebase --abortvs--skip?--abort: Cancels the rebase and resets to the original pre-rebase state.--skip: Discards the current conflicting commit entirely and continues rebasing remaining commits.
What is
git merge --abort?Cancels a conflicted merge and restores the pre-merge state cleanly.
What is
git log -S "string"(Pickaxe)?Searches commit history for commits that added or deleted occurrences of the specified text string.
What is
git log -G "regex"?Searches commit history for commits whose patch diffs match the specified regular expression.
What is
git log --follow <file>?Tracks file history across historical file renames and moves.
What is
git format-patch -1 <sha>?Generates an emailable patch file representing a single specific commit.