Git and GitHub Interview Questions and Answers for Freshers (2026)

Almost every software job today asks at least two or three Git questions, even in a fresher interview. Recruiters check it because every company uses Git every day, and a fresher who can create a branch, raise a pull request and fix a merge conflict is ready to work from day one.
Download these notes as a PDF (with diagrams and examples)
We collected the Git and GitHub questions that come up most in campus placements and off-campus interviews for service and product companies, and wrote short, simple answers with the exact commands. Read them once, then open a terminal and try each command yourself. Interviewers can tell the difference.
Quick summary
| Area | What they ask most |
|---|---|
| Basics | Git vs GitHub, repository, commit, staging area |
| Branching | Branch, merge, merge conflict, rebase |
| Undoing work | reset vs revert, checkout, restore, stash |
| Remote work | clone, fetch vs pull, push, fork, pull request |
| Good practice | .gitignore, commit messages, branching strategy |
Basic Git questions
1. What is Git?
Git is a free, open source distributed version control system. It records every change to your files so you can see history, go back to an older version and work in parallel with other people.
2. What is the difference between Git and GitHub?
Git is the tool that runs on your computer. GitHub is a website that hosts Git repositories online and adds pull requests, issues, code review and actions. GitLab and Bitbucket are similar services.
3. What is a distributed version control system?
Every developer has the full copy of the repository with its complete history. You can commit and see history without internet. In a centralised system (like SVN), history lives only on one server.
4. What is a repository?
A folder that Git tracks. It holds your files plus a hidden .git folder with the full history. git init makes a new one; git clone <url> copies an existing one.
5. What are the three states (areas) in Git?
Working directory (where you edit), staging area or index (what will go in the next commit) and the local repository (saved commits). Files move with git add and git commit.
6. What is a commit?
A saved snapshot of the staged changes with a message, author, time and a unique SHA-1 hash ID. Command: git commit -m "Add login page".
7. What does git status do?
It shows which files are changed, which are staged and which are untracked.
8. What is the difference between git add . and git add -A?
In Git 2.x both stage new, changed and deleted files. git add . works on the current folder and below; git add -A works on the whole repository.
9. What is .gitignore?
A file that lists patterns Git should not track, such as node_modules/, .env, build output and log files.
10. How do you see the history of commits?git log, or the short form git log --oneline --graph to see branches as a graph.
Branching and merging
11. What is a branch?
A separate line of work. You create a branch for a feature so the main branch stays stable. git branch feature-login creates it; git switch feature-login (or git checkout) moves to it.
12. What is HEAD?
A pointer to the commit you are on right now, usually the latest commit of the current branch.
13. How do you merge a branch?
Switch to the target branch and run git merge feature-login. Git combines the histories and makes a merge commit if needed.
14. What is a fast-forward merge?
When the target branch has no new commits, Git simply moves its pointer forward to the feature branch. No merge commit is made.
15. What is a merge conflict and how do you fix it?
It happens when two branches change the same lines. Git marks the file with <<<<<<<, ======= and >>>>>>>. You edit the file to keep the right code, then git add and git commit.
16. What is the difference between merge and rebase?
| Merge | Rebase |
|---|---|
| Joins two branches with a merge commit | Moves your commits on top of the other branch |
| Keeps the true history | Makes a clean straight history |
| Safe on shared branches | Do not rebase commits others already pulled |
17. What is git cherry-pick?
It copies one chosen commit from another branch onto your current branch: git cherry-pick <commit-id>.
18. What is a tag?
A fixed name for a commit, usually a release like v1.0. git tag v1.0 then git push origin v1.0.
Undoing changes
19. What is the difference between git reset and git revert?git revert <id> makes a new commit that undoes an old one, so history stays safe for others. git reset moves the branch pointer back and can remove commits from history; use it only on your own local work.
20. Explain git reset --soft, --mixed and --hard.
Soft keeps changes staged, mixed (default) keeps changes but unstaged, hard deletes the changes completely.
21. What is git stash?
It saves your unfinished changes and cleans the working directory, so you can switch branches. git stash pop brings them back.
22. How do you change the last commit message?git commit --amend -m "New message" (only if it is not pushed yet).
23. How do you discard changes in a file?git restore file.txt (newer) or git checkout -- file.txt (older).
24. What is git reflog?
A log of everywhere HEAD has been. It helps you recover commits even after a hard reset.
Working with remotes and GitHub
25. What is a remote and what is origin?
A remote is a copy of the repository on a server. origin is the default name given to the one you cloned from.
26. Difference between git fetch and git pull?git fetch downloads new commits but does not change your files. git pull is fetch plus merge (or rebase) into your current branch.
27. What does git push do?
It uploads your local commits to the remote branch: git push origin main.
28. What is a fork?
Your own copy of someone else’s repository on GitHub. You change it and send a pull request to the original.
29. What is a pull request?
A request to merge your branch into another branch, with a place for code review, comments and checks before merging.
30. What is the difference between clone and fork?
Clone copies a repository to your computer. Fork copies it to your GitHub account.
31. What is GitHub Actions?
GitHub’s built-in CI/CD. A YAML file in .github/workflows runs tests or deploys code on every push or pull request.
Practice and scenario questions
32. You committed to the wrong branch. What do you do?
Note the commit ID, switch to the right branch and git cherry-pick <id>, then go back and remove it with git reset --hard HEAD~1 (if not pushed).
33. What makes a good commit message?
Short summary line under about 50 characters in present tense (“Fix login error”), then a blank line and details if needed. One logical change per commit.
34. What is a branching strategy? Name one.
A team rule for branches. Git Flow uses main, develop, feature, release and hotfix branches. Trunk based development keeps short feature branches merged into main often.
35. What is the difference between git diff and git diff --staged?git diff shows unstaged changes; git diff --staged shows what is staged for the next commit.
Commands to remember
| Task | Command |
|---|---|
| Start a repo | git init |
| Copy a repo | git clone <url> |
| Stage and save | git add . then git commit -m "msg" |
| New branch | git switch -c feature |
| Merge | git merge feature |
| Update from server | git pull |
| Send to server | git push origin main |
| Undo safely | git revert <id> |
| Save work for later | git stash / git stash pop |
How to prepare in one evening
- Make a free GitHub account and push one small project. Put the link on your resume.
- Practise a merge conflict on purpose with two branches. Many interviewers ask you to explain the steps.
- Learn reset vs revert, fetch vs pull and merge vs rebase well. These three are asked the most.
More interview prep
- Linux interview questions
- DSA interview questions
- SQL interview questions
- HR interview questions
- Free notes for every subject: Study Material




Doubts? Ask here