DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

Git & GitHub · interview practice

Git & GitHub interview questions

Answer each one out loud first, then tap it to check yourself against a model answer and the lesson behind it.

The basics 1Repositories 2Branching 2GitHub essentials 2Remotes 3Merge strategies 2Collaboration 2Undoing changes 2History & diffs 2Rewriting history 2Tags & releases 2Hooks & automation 2Security & extras 1

The basics

Q1A teammate overwrote a file in a shared folder. What does version control give you that the folder does not?junior

Git records snapshots and lets the team compare, restore and branch from earlier states. Each change has an author and commit message, so we can discuss a specific change instead of copying files around.

Read the lesson: Version control, and setting Git up once →

Repositories

Q2What does git add do, and does it create a commit?junior

git add copies selected changes into Git's staging area, which is the proposed content of the next commit. It does not create the commit; git commit records the staged snapshot.

Read the lesson: Commits: the working folder, the staging area and history →
Q3A new file appears as ?? in git status --short. What does that mean?junior

Git sees an untracked file that is not yet included in version control. I inspect it for secrets and generated files, then either add it intentionally or update .gitignore if it should stay out.

Read the lesson: Commits: the working folder, the staging area and history →

Branching

Q4What is a Git branch technically?junior

A branch is a movable reference to a commit, not a separate copy of the whole repository. New commits on the branch move that reference forward while the shared history remains available.

Read the lesson: Branches: work on many things without breaking main →
Q5How do you create a branch and switch to it in one command?junior

I use git switch -c followed by a descriptive branch name. Before editing, I check git status and confirm the new branch is based on the intended starting point.

Read the lesson: Branches: work on many things without breaking main →

GitHub essentials

Q6What is the difference between Git and GitHub?junior

Git is the version-control tool that stores repository history. GitHub hosts Git repositories and adds collaboration features such as pull requests, issues and code review.

Read the lesson: GitHub: your account, repositories, forks and clones →
Q7When should a GitHub repository be public or private?junior

I make it public only when its contents are intended for anyone to read and contain no secrets or restricted material. Otherwise I keep it private and grant access to the people who need it.

Read the lesson: GitHub: your account, repositories, forks and clones →

Remotes

Q8What does adding a remote to a local repository let you do?junior

A remote gives the local repository a named URL for another copy, often hosted on GitHub. I can fetch from it or push commits to it, subject to the repository's access rules.

Read the lesson: Remotes: push, fetch and pull without surprises →
Q9What does git fetch change in your local repository?junior

It downloads remote commits and updates remote-tracking references, but it does not merge them into my current branch or change my working files. I inspect the incoming history before choosing how to integrate it.

Read the lesson: Remotes: push, fetch and pull without surprises →
Q10Your local branch is ahead of origin by one commit. What does that tell you?junior

My branch contains one commit that the tracked remote branch does not yet have. I review the commit and push it if it is ready and I have permission to update that branch.

Read the lesson: Remotes: push, fetch and pull without surprises →

Merge strategies

Q11When would you choose a merge commit instead of rebasing?mid

I merge when I want to preserve the fact that two lines of work came together, especially on shared history. A merge commit records both parent commits and avoids rewriting commits other people may already use.

Read the lesson: Merge, rebase, squash: combining work, and fixing conflicts →
Q12What is the golden rule of rebasing?mid

I do not rebase commits that other people may already have based work on. Rebasing creates new commit IDs, so on shared branches it can make collaborators reconcile two versions of the same history.

Read the lesson: Merge, rebase, squash: combining work, and fixing conflicts →

Collaboration

Q13What problem does a pull request solve in a team workflow?mid

A pull request proposes a branch's changes for discussion, automated checks and review before they reach the target branch. It gives reviewers a focused diff and a place to record decisions.

Read the lesson: Collaboration: issues, pull requests and code review →
Q14How do you make a code review comment useful rather than just critical?mid

I point to a concrete behavior or risk, explain why it matters, and suggest a next step or ask a focused question. I distinguish a required fix from an optional preference so the author can act clearly.

Read the lesson: Collaboration: issues, pull requests and code review →

Undoing changes

Q15A commit has already been pushed to a shared branch and must be undone. Which approach is safer?mid

I use git revert to create a new commit that reverses the target change. It preserves the shared history instead of moving the branch pointer and disrupting collaborators.

Read the lesson: Undoing changes: revert, reset, stash and reflog →
Q16You need to switch tasks but have unfinished edits that are not ready to commit. What can you do?mid

I can use git stash to save the working changes temporarily, then restore them when I return. Before applying a stash I check the current branch and working tree so I do not mix unrelated work.

Read the lesson: Undoing changes: revert, reset, stash and reflog →

History & diffs

Q17How would you find which commit introduced a particular string in the repository?mid

I search history with git log -S followed by the string, then inspect the matching commit and its diff. This narrows the history to changes where the number of occurrences changed.

Read the lesson: History and diffs: find what changed, who changed it, and when it broke →
Q18What is the risk of using git blame without checking the surrounding history?mid

Blame attributes the current line to the last commit that changed it, but formatting or moving code can make that attribution misleading. I use options that track moved or copied lines and inspect the commit diff for context.

Read the lesson: History and diffs: find what changed, who changed it, and when it broke →

Rewriting history

Q19You need to fix the message of your last commit, and nobody else has fetched it. What do you do?mid

I amend the commit with git commit --amend after checking the staged content. The amended commit gets a new ID, so I only do this while the commit is still private to my branch.

Read the lesson: Rewriting history: amend, interactive rebase and safe force-pushes →
Q20In an interactive rebase, what is the difference between squash and fixup?mid

Both combine a commit into the previous one. squash lets me edit the combined commit message, while fixup discards the later commit's message and keeps the earlier one.

Read the lesson: Rewriting history: amend, interactive rebase and safe force-pushes →

Tags & releases

Q21Why use an annotated Git tag for a release?senior

An annotated tag stores a message, tagger and timestamp, so it records release context rather than only pointing at a commit. I can then push the tag and use it as a stable release marker.

Read the lesson: Tags and releases: version numbers people can trust →
Q22How should a team connect semantic version numbers with Git releases?senior

We agree what breaking, compatible and patch changes mean, then tag the chosen release commit with that version. The release notes should describe user-visible changes; a tag alone does not explain them.

Read the lesson: Tags and releases: version numbers people can trust →

Hooks & automation

Q23A pre-commit hook rejects a change. How should the developer respond?senior

A non-zero hook exit blocks the commit, so I read its output, fix the reported issue and run it again. I avoid bypassing the hook unless there is a documented reason and an equivalent check will run elsewhere.

Read the lesson: Hooks and automation: let Git check your work →
Q24A GitHub Actions workflow needs to access a private repository. How do you avoid putting a long-lived token in the workflow file?senior

I use the repository's provided GITHUB_TOKEN with only the permissions the workflow needs, or a narrowly scoped secret when cross-repository access requires it. I never commit the credential and review which events can access it.

Read the lesson: Hooks and automation: let Git check your work →

Security & extras

Q25A developer committed a credential and then deleted the line. What should happen next?senior

I treat the credential as exposed and revoke or rotate it first; deleting the current line does not remove it from Git history. Then I check for misuse, remove it from history if appropriate, and add prevention such as push protection.

Read the lesson: Security and extras: secrets, Dependabot, LFS, submodules and Pages →
← Back to the Git & GitHub course