Git & GitHub Interview Questions Interview Questions and Answers

Practice every question in this topic using expandable answers and interview tips. Answer aloud first, then open the explanation.

Back to the complete interview hub

Read question Answer aloud Review
Q1. What is Git? [Easy]

Answer: Git is a free, open-source Distributed Version Control System (DVCS) designed to handle everything from small to very large projects with speed and efficiency. It tracks changes in source code over time.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q2. What is the difference between Git and GitHub? [Easy]

Answer: Git is the command-line version control software installed on your local machine. GitHub is a cloud-based hosting service that lets you manage Git repositories and facilitates collaboration, code review, and CI/CD.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q3. What is the purpose of the .gitignore file? [Easy]

Answer: The .gitignore file tells Git which files or directories to ignore and not track. This is commonly used for build artifacts, log files, node_modules, or files containing sensitive credentials.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q4. What is the difference between 'git fetch' and 'git pull'? [Easy]

Answer: 'git fetch' downloads commits, files, and refs from a remote repository into your local repo but does not integrate them into your working copy. 'git pull' does a fetch and immediately merges the changes into your current working branch.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q5. What is 'git stash' and when would you use it? [Medium]

Answer: 'git stash' temporarily shelves (or stashes) changes you've made to your working directory so you can work on something else (like switching branches) without having to commit half-done work. You can restore them later using 'git stash pop'.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q6. What is a merge conflict and how do you resolve it? [Medium]

Answer: A merge conflict occurs when Git cannot automatically resolve differences in code between two commits (e.g., two developers edited the same line of code). To resolve it, you must manually edit the conflicting files to choose the correct changes, stage the resolved files, and commit them.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q7. What is the difference between 'git merge' and 'git rebase'? [Hard]

Answer: 'git merge' takes changes from one branch and integrates them into another by creating a new 'merge commit', preserving full history. 'git rebase' moves the feature branch's commits to the tip of the master branch, rewriting history to create a clean, linear project history.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q8. What is the difference between 'git reset' and 'git revert'? [Medium]

Answer: 'git reset' moves the HEAD pointer backward to a previous commit, effectively erasing history (bad for shared branches). 'git revert' creates a brand-new commit that safely undoes the changes made by a previous commit, preserving history (ideal for shared branches).

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q9. What are the different types of 'git reset'? [Hard]

Answer: There are three main types: '--soft' (moves HEAD, keeps changes in Staging), '--mixed' (default, moves HEAD, moves changes from Staging to Working Directory), and '--hard' (moves HEAD and completely discards all tracked uncommitted changes).

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q10. What is 'git cherry-pick'? [Hard]

Answer: Git cherry-pick is a command that allows you to select a single specific commit from one branch and apply it to another branch, without merging the entire branch.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q11. How do you modify the most recent commit message? [Medium]

Answer: You can modify the most recent commit by using the command 'git commit --amend'. This allows you to change the commit message or add forgotten files to the last commit, rewriting that commit's history.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q12. What is 'git reflog'? [Hard]

Answer: The 'git reflog' (Reference Logs) is an internal Git mechanism that records every movement of the HEAD pointer in your local repository. It is extremely useful for recovering 'lost' commits, deleted branches, or undoing a disastrous rebase.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q13. What is a Pull Request (PR) in GitHub? [Medium]

Answer: A Pull Request is a feature specific to Git hosting platforms like GitHub. It is a request for repository maintainers to review, discuss, and merge code changes from a feature branch or fork into the main branch.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q14. What is the difference between Forking and Cloning? [Easy]

Answer: Forking creates a personal, server-side copy of someone else's repository on your GitHub account. Cloning creates a local copy of a remote repository on your physical machine.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q15. What are GitHub Actions? [Medium]

Answer: GitHub Actions is a built-in CI/CD (Continuous Integration and Continuous Deployment) platform that allows you to automate software workflows directly within your GitHub repository, such as testing code, building binaries, or deploying applications.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Study checklist

  1. Explain the answer without reading.
  2. Write one small example.
  3. Compare framework or database version differences in official documentation.

Git & GitHub Interview Questions Interview Questions and Answers

Practice one question at a time. Read the question, answer aloud, then compare your explanation with the answer.

← Back to the complete interview hub

Study method: define the concept, give a small example, and mention one practical use or limitation.

Q1. What is Git?

Easy

Answer: Git is a free, open-source Distributed Version Control System (DVCS) designed to handle everything from small to very large projects with speed and efficiency. It tracks changes in source code over time.

Interview tip: Use a short example and connect the answer to real project work.

Q2. What is the difference between Git and GitHub?

Easy

Answer: Git is the command-line version control software installed on your local machine. GitHub is a cloud-based hosting service that lets you manage Git repositories and facilitates collaboration, code review, and CI/CD.

Interview tip: Use a short example and connect the answer to real project work.

Q3. What is the purpose of the .gitignore file?

Easy

Answer: The .gitignore file tells Git which files or directories to ignore and not track. This is commonly used for build artifacts, log files, node_modules, or files containing sensitive credentials.

Interview tip: Use a short example and connect the answer to real project work.

Q4. What is the difference between 'git fetch' and 'git pull'?

Easy

Answer: 'git fetch' downloads commits, files, and refs from a remote repository into your local repo but does not integrate them into your working copy. 'git pull' does a fetch and immediately merges the changes into your current working branch.

Interview tip: Use a short example and connect the answer to real project work.

Q5. What is 'git stash' and when would you use it?

Medium

Answer: 'git stash' temporarily shelves (or stashes) changes you've made to your working directory so you can work on something else (like switching branches) without having to commit half-done work. You can restore them later using 'git stash pop'.

Interview tip: Use a short example and connect the answer to real project work.

Q6. What is a merge conflict and how do you resolve it?

Medium

Answer: A merge conflict occurs when Git cannot automatically resolve differences in code between two commits (e.g., two developers edited the same line of code). To resolve it, you must manually edit the conflicting files to choose the correct changes, stage the resolved files, and commit them.

Interview tip: Use a short example and connect the answer to real project work.

Q7. What is the difference between 'git merge' and 'git rebase'?

Hard

Answer: 'git merge' takes changes from one branch and integrates them into another by creating a new 'merge commit', preserving full history. 'git rebase' moves the feature branch's commits to the tip of the master branch, rewriting history to create a clean, linear project history.

Interview tip: Use a short example and connect the answer to real project work.

Q8. What is the difference between 'git reset' and 'git revert'?

Medium

Answer: 'git reset' moves the HEAD pointer backward to a previous commit, effectively erasing history (bad for shared branches). 'git revert' creates a brand-new commit that safely undoes the changes made by a previous commit, preserving history (ideal for shared branches).

Interview tip: Use a short example and connect the answer to real project work.

Q9. What are the different types of 'git reset'?

Hard

Answer: There are three main types: '--soft' (moves HEAD, keeps changes in Staging), '--mixed' (default, moves HEAD, moves changes from Staging to Working Directory), and '--hard' (moves HEAD and completely discards all tracked uncommitted changes).

Interview tip: Use a short example and connect the answer to real project work.

Q10. What is 'git cherry-pick'?

Hard

Answer: Git cherry-pick is a command that allows you to select a single specific commit from one branch and apply it to another branch, without merging the entire branch.

Interview tip: Use a short example and connect the answer to real project work.

Q11. How do you modify the most recent commit message?

Medium

Answer: You can modify the most recent commit by using the command 'git commit --amend'. This allows you to change the commit message or add forgotten files to the last commit, rewriting that commit's history.

Interview tip: Use a short example and connect the answer to real project work.

Q12. What is 'git reflog'?

Hard

Answer: The 'git reflog' (Reference Logs) is an internal Git mechanism that records every movement of the HEAD pointer in your local repository. It is extremely useful for recovering 'lost' commits, deleted branches, or undoing a disastrous rebase.

Interview tip: Use a short example and connect the answer to real project work.

Q13. What is a Pull Request (PR) in GitHub?

Medium

Answer: A Pull Request is a feature specific to Git hosting platforms like GitHub. It is a request for repository maintainers to review, discuss, and merge code changes from a feature branch or fork into the main branch.

Interview tip: Use a short example and connect the answer to real project work.

Q14. What is the difference between Forking and Cloning?

Easy

Answer: Forking creates a personal, server-side copy of someone else's repository on your GitHub account. Cloning creates a local copy of a remote repository on your physical machine.

Interview tip: Use a short example and connect the answer to real project work.

Q15. What are GitHub Actions?

Medium

Answer: GitHub Actions is a built-in CI/CD (Continuous Integration and Continuous Deployment) platform that allows you to automate software workflows directly within your GitHub repository, such as testing code, building binaries, or deploying applications.

Interview tip: Use a short example and connect the answer to real project work.

Quick revision checklist

  1. Explain the answer without reading.
  2. Write one small example.
  3. Review platform or version differences in official documentation.

logoblog

No comments:

Post a Comment

Please do not enter any spam link in the comment box.