qa

Perfect! Let’s cover all common Git interview questions in a structured way so you can recall quickly. I’ll include commands, concepts, and some advanced scenarios that usually repeat in interviews.


1️⃣ Basic Git Concepts

Topic
Notes / Common Questions

What is Git?

Distributed version control system, tracks changes, enables collaboration.

Difference between Git and GitHub?

Git = tool, GitHub = remote hosting platform.

Git vs SVN

Git is distributed, SVN centralized; Git supports offline commits, branching is lightweight.

Staging area

Files added via git add are staged before commit.

Commit

git commit -m "message" – snapshots changes from staging area.


2️⃣ Common Git Commands

Task
Command
Notes

Initialize repo

git init

Creates local repo

Clone repo

git clone <url>

Copy remote repo locally

Check status

git status

Shows modified, staged, untracked files

Stage changes

git add <file>

Add file to staging area

Commit changes

git commit -m "msg"

Commit staged changes

Push changes

git push origin <branch>

Send commits to remote

Pull changes

git pull

Fetch + merge from remote

Fetch only

git fetch

Get updates from remote without merge

Show commit history

git log

Use --oneline for short view

Show diff

git diff

Compare unstaged changes

Undo last commit

git reset --soft HEAD~1

Keeps changes staged

Hard reset

git reset --hard HEAD~1

Discards changes


3️⃣ Branching & Merging

Topic
Explanation / Commands

Create branch

git branch <branch>

Switch branch

git checkout <branch> or git switch <branch>

Create + switch

git checkout -b <branch> or git switch -c <branch>

Merge branch

git merge <branch>

Resolve conflicts

Manually edit files, then git add + git commit

Rebase

git rebase <branch> – move commits on top of another branch

Delete branch

git branch -d <branch> (local) / git push origin --delete <branch> (remote)

Stash

git stash → temporarily store changes not ready to commit

Apply stash

git stash apply or git stash pop


4️⃣ Remote & Collaboration

Topic
Commands / Notes

Add remote

git remote add origin <url>

Show remotes

git remote -v

Fetch remote

git fetch

Pull + merge

git pull

Push local branch

git push origin <branch>

Set upstream branch

git push -u origin <branch>


5️⃣ Advanced / Interview-focused Questions

Question
Notes / Command

Difference merge vs rebase

Merge = creates a merge commit; rebase = rewrites history, linearizes commits

Git cherry-pick

git cherry-pick <commit> → apply specific commit to current branch

Undo last commit

git revert HEAD → safe for shared branches (creates new commit)

Difference git reset --hard vs git checkout -- <file>

Reset discards commits; checkout discards file changes

Git reflog

git reflog → see all recent actions including lost commits

Squash commits

git rebase -i HEAD~n → combine commits for cleaner history

Detached HEAD

HEAD points to a commit instead of a branch; any new commit here may be lost

Git tagging

git tag v1.0 → lightweight tag; git push origin v1.0 to remote

Submodules

git submodule add <repo> → include repo inside another repo

Conflict resolution

git merge → conflict markers <<<<<< → manually resolve → git addgit commit

Stashing multiple

git stash save "msg"git stash listgit stash pop stash@{1}


6️⃣ Git Workflow Questions

  • Explain your Git workflow: Example: feature branch → develop branch → PR → code review → merge → main branch

  • How do you handle conflicts in PR? → Rebase / merge + manual resolution

  • How to rollback production changes?git revert for safety, git reset only for local/private branch


7️⃣ Tips for Speaking in Interviews

  • Always explain why you use a command, not just the syntax.

  • Show awareness of safe practices: revert vs reset, force push dangers.

  • Mention branching strategy you follow: Git Flow, trunk-based, etc.

  • Use examples from your own work if possible.


If you want, I can make a 1-page “Git cheat sheet” for interview, covering all repeated questions + commands + tips, so you can quickly revise before your interview.

Do you want me to make that?

Last updated