51 Git Interview Questions And Answers 2024

1. What is the difference between Git and SVN?

2. What is Git?

3. What is distributed VCS?

4. What is the difference between Git and Github?

5. What are the benefits of using version Control System?

6. What language is used in Git?

7. Mention the various Git repository hosting functions.

8. What is a commit message?

9. How can you fix a broken commit?

10. What is a repository in Git?

11. How can you create a repository in Git?

12. What is ‘bare repository’ in Git?

13. What is a ‘conflict’ in git?

14. How is git instaweb used?

15. What is git is-tree?

16. Name a few Git commands and explain their usage.

17. How to resolve a conflict in Git?

18.In Git how do you revert a commit that has already been pushed and made public?

19.What is SubGit?

20.What is the difference between git pull and git fetch?

21. What is ‘staging area’ or ‘index’ in Git?

22. What work is restored when the deleted branch is recovered?

23. What is git stash?

24. What is the function of ‘git stash apply’?

25. What is the difference between the ‘git diff ’and ‘git status’?

26.  What is the difference between ‘git remote’ and ‘git clone’?

27.  What is git stash drop?

28. How do you find a list of files that have changed in a particular commit?

29.  What is the function of ‘git config’?

30. What does a commit object contain?

31. Describe the branching strategies you have used.

32. Explain the advantages of forking workflow

33. How will you know in Git if a branch has already been merged into master?

34. Why is it desirable to create an additional commit rather than amending an existing commit?

35. What does ‘hooks’ comprise of in Git?

36. In Git, how would you return a commit that has just been pushed and made open?

37. How to remove a file from git without removing it from your file system?

38. Can you explain the Gitflow workflow?

39. Tell me the difference between HEAD, working tree and index, in Git.

40.  What is Git fork? What is the difference between fork, branch, and clone?

41. What are the different ways you can refer to a commit?

42. What is the difference between rebasing and merge in Git?

43. . Explain the difference between reverting and resetting.

44. What is git cherry-pick?

45. How do you find a list of files that have changed in a particular commit?

46. How do you squash the last N commits into a single commit?

47. What is Git bisect? How can you use it to determine the source of a (regression) bug?

48. How do you configure a Git repository to run code sanity checking tools right before making commits, and preventing them if the test fails?

49.  How do you integrate Git with Jenkins?

50. What is git reflog?

51. How to recover a deleted branch using git reflog?

Git Interview Questions And Answers

1. What is the difference between Git and SVN?

Ans.

Git:

  • Distributed vs. Centralized: Git is a distributed version control system (DVCS), meaning that every developer’s working copy of the code is also a repository that can contain the full history of all changes. This makes it more flexible in terms of collaboration and allows for offline work.
  • Branching: Git encourages branching and merging as an integral part of the development process. Creating and merging branches is fast and efficient.
  • Performance: Git is generally faster than SVN, especially for operations like branching and merging.

SVN (Subversion):

  • Centralized: SVN, on the other hand, is a centralized version control system. There is a central repository that contains all the files, and developers need to connect to it to commit changes or get the latest version.
  • Branching and Merging: While SVN supports branching and merging, it can be more cumbersome than Git, and it often involves more manual intervention.
  • History Storage: SVN doesn’t store the full history of the project on the local machine; instead, it keeps track of the differences between the working copy and the central repository.

2. What is Git?

Ans. Git: Git is a distributed version control system (DVCS) designed to handle everything from small to very large projects with speed and efficiency. It was created by Linus Torvalds in 2005. Git allows multiple developers to collaborate on a project, tracking changes in source code during software development.

3. What is a distributed VCS?

Ans. Distributed Version Control System (DVCS): In a DVCS, each developer’s local copy of the repository is a complete copy of the entire project, including its full history. This allows for greater flexibility, offline work, and efficient collaboration among developers.

4. What is the difference between Git and GitHub?

Ans.Git: Git is the version control system itself, a tool for tracking changes in source code during software development.

GitHub: GitHub is a web-based platform that uses Git for version control. It provides hosting for software development and offers features like collaboration, bug tracking, and task management. GitHub is one of many platforms that can be used with Git.

5. What are the benefits of using Version Control System?

Ans.

  • Collaboration: Multiple developers can work on the same project simultaneously without interfering with each other’s work.
  • Versioning: Tracks changes to files over time, allowing you to revert to previous versions if needed.
  • Branching and Merging: Supports parallel development through branching, and merging allows integrating changes from different branches.
  • History Tracking: Maintains a complete history of changes, including who made them and when.
  • Backup and Recovery: Acts as a backup system, reducing the risk of data loss.
  • Conflict Resolution: Helps in managing conflicts that may arise when multiple developers are working on the same code.

6. What language is used in Git?

Ans. Git: Git is primarily written in C, with a small core of scripts written in Perl and a few shell scripts.

7. Mention the various Git repository hosting functions.

Ans. Various Git repository hosting platforms provide functions such as:

  • Code Hosting: Storing and managing the source code of projects.
  • Collaboration: Facilitating collaboration among developers through features like pull requests, code reviews, and issue tracking.
  • Access Control: Managing permissions to control who can contribute to a project.
  • Integration: Integrating with other tools and services to streamline development workflows.

8. What is a commit message?

Ans, Commit Message: A commit message is a brief and descriptive comment that accompanies a commit in version control systems like Git. It explains the purpose of the commit, what changes were made, and often includes context to help other developers understand the modification.

9. How can you fix a broken commit?

Ans. To fix a broken commit, you can:

  1. Amend the Commit: Use the --amend option with the git commit command to add changes to the previous commit.
  2. Interactive Rebase: Use git rebase -i to interactively rebase and modify commits.
  3. Reset and Commit Again: Use git reset to undo the last commit and then commit the changes again.

10. What is a repository in Git?

Ans. Repository: In Git, a repository (repo) is a collection of files and version control data, including the full history of changes. It can exist either locally on a developer’s machine or remotely on a server.

11. How can you create a repository in Git?

Ans. To create a repository in Git, you can use the following commands:

# Create a new directory for your project
$ mkdir my_project

# Navigate to the project directory
$ cd my_project

# Initialize a new Git repository
$ git init

12. What is a ‘bare repository’ in Git?

Ans. Bare Repository: A bare repository in Git is a repository that doesn’t contain a working directory. It only consists of the version control information. Bare repositories are typically used as central repositories where developers can push and pull changes but cannot directly work on files.

13. What is a ‘conflict’ in Git?

Ans. Conflict in Git: A conflict in Git occurs when two or more branches have made changes to the same part of a file. Git is unable to automatically merge these changes because it doesn’t know which version to choose. Resolving a conflict involves manually editing the conflicted files to decide how the final merged version should look.

14. How is git instaweb used?

Ans. git instaweb: The git instaweb command launches a web server that allows you to browse your Git repository using a web browser. It provides a simple web interface to view the commit history and files.

15. What is git is-tree?

Ans. There isn’t a direct Git command named git is-tree. It seems like there might be a typo or misunderstanding. If you meant something else, please provide clarification, and I’ll be happy to help.

Hridhya Manoj

Hello, I’m Hridhya Manoj. I’m passionate about technology and its ever-evolving landscape. With a deep love for writing and a curious mind, I enjoy translating complex concepts into understandable, engaging content. Let’s explore the world of tech together

Leave a Comment