This guide turns a long list of interview prompts into practical answers for engineers preparing for DevOps, platform, and software delivery roles. You will review core Git concepts, command-level examples, and where Git, GitHub, and GitLab fit in day-to-day team workflows.
Originally published on 2014-08-18; fully revised and updated.
Original post: Git Interview Questions and Answer Part – 6.

What interviewers usually test
Most Git interview rounds check whether you can explain concepts and apply them with commands. Expect a mix of fundamentals, branch strategy, collaboration flow, and incident recovery.
- Core concepts: repository, commit, staging area, HEAD, branch, merge, rebase
- Daily command fluency: status, diff, add, commit, log, pull, push
- Collaboration: pull/merge requests, conflict resolution, branch cleanup
- Platform awareness: GitHub vs GitLab and CI/CD integration
- Troubleshooting: auth failures, diverged branches, bad commits
Core Git interview questions and concise answers
- What is Git? Git is a distributed version control system that tracks file changes and enables collaborative development.
- What is a repository? A repository (repo) stores project files plus history (commits, branches, tags).
- What is the staging area (index)? It is an intermediate area where you select exactly what goes into the next commit.
- What does
git commit -mdo? It records staged changes and attaches the provided commit message. - What does
git pushdo? It sends local commits to a remote repository reference (for example,origin/main). - What is
git cloneused for? It copies an existing remote repository locally, including history and refs. - What is the difference between
git remoteandgit clone?git clonecreates a local copy;git remotemanages remote names and URLs in an existing local repo. - What is HEAD? HEAD is a reference to your current checked-out commit (typically the tip of the active branch).
- What is a bare repository? A repository without a working tree, commonly used as a central/shared remote.
- What is
git stash? It temporarily shelves uncommitted changes so you can switch context safely. - What does
git stash dropdo? It removes a stored stash entry after you no longer need it. - What does a commit object contain? A snapshot reference (tree), parent commit reference(s), author/committer metadata, timestamps, and message.
- What language is Git written in? Git core is primarily written in C, with supporting tooling historically including shell and Perl scripts.
- How is Git different from SVN? Git is distributed and local-first; SVN is centralized with a single canonical repository workflow.
Essential commands you should be able to explain
Interviewers often ask you to narrate what each command does and when you would choose it.
# Initialize or copy a repository
git init
git clone https://example.com/team/app.git
# Inspect local state
git status
git diff
git log --oneline --graph --decorate -n 10
# Stage and commit
git add .
git commit -m "Implement health endpoint"Code language: PHP (php)
# Branching and integration
git checkout -b feature/health-endpoint
git push -u origin feature/health-endpoint
git checkout main
git pull origin main
git merge feature/health-endpoint
# Alternative integration style
# git rebase mainCode language: PHP (php)
# Stash and conflict handling
git stash
git stash list
git stash apply stash@{0}
git stash drop stash@{0}
# Undo and recovery patterns
git restore --staged FILE_NAME
git restore FILE_NAME
git revert COMMIT_SHACode language: PHP (php)
Feature branch workflow from local work to merge
flowchart LR
A[Clone repository] --> B[Create feature branch]
B --> C[Commit local changes]
C --> D[Push branch to remote]
D --> E[Open pull or merge request]
E --> F[Review and CI checks]
F --> G{Approved}
G -- No --> C
G -- Yes --> H[Merge into main]
H --> I[Delete feature branch]
Git, SVN, GitHub, and GitLab comparisons
Git vs SVN
| Aspect | Git | SVN |
|---|---|---|
| Model | Distributed version control | Centralized version control |
| Local commits | Yes | No (commit to central server) |
| Branching | Lightweight and commonly used | Supported, often treated as heavier workflow |
| Offline work | Strong (most operations local) | Limited for commit/history operations |
| Typical modern ecosystem | Strong integration with PR/MR workflows and CI/CD platforms | Still used in some legacy/centralized environments |
GitHub vs GitLab
| Aspect | GitHub | GitLab |
|---|---|---|
| Primary role | Git hosting and collaboration platform | Git hosting plus integrated DevOps platform |
| Code review unit | Pull request | Merge request |
| Built-in CI/CD | GitHub Actions | GitLab CI/CD |
| Deployment model | Cloud and enterprise/self-hosted offerings | GitLab.com and self-managed offerings |
| Permissions and governance | Repository and organization controls | Project/group controls with role-based access |
| Common interview framing | Open-source collaboration and ecosystem | Single-platform SDLC and integrated pipelines |
Command intent comparison: status, diff, and log
| Command | What it shows | Typical interview explanation |
|---|---|---|
git status | Current branch, staged and unstaged changes | “What is the repo state right now?” |
git diff | Line-level content differences | “What exactly changed in files?” |
git log | Commit history | “How has the project evolved over time?” |
Advanced topics often asked
- Git objects: blob (file content), tree (directory snapshot), commit (history node), tag (named reference).
git ls-tree: Lists contents of a tree object (commonly used for object-level inspection).- Hooks: Script entry points such as pre-commit, pre-push, and server-side hooks for policy enforcement.
- Merge vs rebase: Merge preserves branch topology; rebase rewrites commit base for a linear history.
- SubGit: Commonly referenced as a bridge/migration tool between SVN and Git repositories.
- Atlassian Stash: Historical product name; now commonly known as Bitbucket Server/Data Center.
# Object and tree inspection examples
git cat-file -p HEAD
git ls-tree HEAD
# Check whether a branch is already merged
git branch --merged main
# Delete local and remote branch
git branch -d feature/old-work
git push origin --delete feature/old-workCode language: PHP (php)
Troubleshooting checklist for Git, GitHub, and GitLab
- Verify branch, staged state, and pending changes before pull/push.
- Confirm remote URLs and expected upstream tracking branch.
- Check authentication mode (SSH vs HTTPS) and token/key validity.
- Inspect divergence before force operations; prefer revert over history rewrite on shared branches.
- For GitLab administration tasks such as backups, validate commands against your exact edition and deployment method.
# Quick diagnostics
git status
git branch -vv
git remote -v
git config --list --show-origin
# Connectivity checks
ssh -T git@github.com
ssh -T git@gitlab.com
# Example often used on Omnibus-based GitLab installations
# gitlab-backup createCode language: PHP (php)
The original post also included a YouTube embed that currently appears without a specific video ID. The preserved related link is: steps in this video.
Common pitfalls in interviews
- Confusing
git fetch,git pull, andgit push. - Using “GitHub” and “Git” as if they are the same thing.
- Explaining merge and rebase without discussing history implications.
- Using destructive commands (
reset --hard, force push) without safety context. - Giving definitions without demonstrating command-level understanding.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals