Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🟣 Git Interview Questions Answered to help you get ready for your next tech interview.

NavyaDevOps18/git-interview-questions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

πŸ–² 36 Git interview questions and answers every developer should know in 2021

Git is the most popular and advanced version control system. it’s the VCS used for the Linux kernel, and was developed by Linus Torvalds. Follow along and check the latest list of 36 Git interview questions that will help you prepare for the next tech interview.



You can also find all 36 answers here πŸ‘‰πŸΌ https://devinterview.io/dev/git-interview-questions


Fetch

πŸ”Ή 1. What is the command to write a commit message in Git?

Answer:

Use:

git commit -a

-a on the command line instructs git to commit the new content of all tracked files that have been modified. You can use

git add <file>

or

git add -A

before git commit -a if new files need to be committed for the first time.

Source: edureka.co


πŸ”Ή 2. What is difference between Git vs SVN?

Answer:

The main point in Git vs SVN debate boils down to this: Git is a distributed version control system (DVCS), whereas SVN is a centralized version control system.

Source: medium.com


πŸ”Ή 3. What is Git?

Answer:

Git is a Distributed Version Control system (DVCS). It can track changes to a file and allows you to revert back to any particular change.

Its distributed architecture provides many advantages over other Version Control Systems (VCS) like SVN one major advantage is that it does not rely on a central server to store all the versions of a project’s files.

Source: edureka.co


πŸ”Ή 4. What is the difference between git pull and git fetch?

Answer:

In the simplest terms, git pull does a git fetch followed by a git merge.

  • When you use pull, Git tries to automatically do your work for you. It is context sensitive, so Git will merge any pulled commits into the branch you are currently working in. pull automatically merges the commits without letting you review them first. If you don’t closely manage your branches, you may run into frequent conflicts.

  • When you fetch, Git gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your master branch, you use merge.



πŸ”Ή 5. What's the difference between a pull request and a branch?

Answer:

  • A branch is just a separate version of the code.

  • A pull request is when someone take the repository, makes their own branch, does some changes, then tries to merge that branch in (put their changes in the other person's code repository).



πŸ”Ή 6. What is Git fork? What is difference between fork, branch and clone?

Answer:

  • A fork is a remote, server-side copy of a repository, distinct from the original. A fork isn't a Git concept really, it's more a political/social idea.
  • A clone is not a fork; a clone is a local copy of some remote repository. When you clone, you are actually copying the entire source repository, including all the history and branches.
  • A branch is a mechanism to handle the changes within a single repository in order to eventually merge them with the rest of code. A branch is something that is within a repository. Conceptually, it represents a thread of development.


πŸ”Ή 7. How does the Centralized Workflow work?

Answer:

The Centralized Workflow uses a central repository to serve as the single point-of-entry for all changes to the project. The default development branch is called master and all changes are committed into this branch.

Developers start by cloning the central repository. In their own local copies of the project, they edit files and commit changes. These new commits are stored locally.

To publish changes to the official project, developers push their local master branch to the central repository. Before the developer can publish their feature, they need to fetch the updated central commits and rebase their changes on top of them.

Compared to other workflows, the Centralized Workflow has no defined pull request or forking patterns.

Source: atlassian.com


πŸ”Ή 8. How to undo the most recent commits in Git?

Answer:

Problem

You accidentally committed wrong files to Git, but haven't pushed the commit to the server yet. How can you undo those commits from the local repository?

$ git commit -m "Something terribly misguided" 
$ git reset HEAD~ # copied the old head to .git/ORIG_HEAD
<< edit files as necessary >> 
$ git add ... 
$ git commit -c ORIG_HEAD # will open an editor, which initially contains the log message from the old commit and allows you to edit it


πŸ”Ή 9. You need to update your local repos. What git commands will you use?

Answer:

It’s a two steps process. First you fetch the changes from a remote named origin:

git fetch origin

Then you merge a branch master to local:

git merge origin/master

Or simply:

git pull origin master

If origin is a default remote and β€˜master’ is default branch, you can drop it eg. git pull.

Source: samwize.com


πŸ”Ή 10. Tell me the difference between HEAD, working tree and index, in Git?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 11. Could you explain the Gitflow workflow?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 12. How to revert previous commit in git?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 13. Explain the advantages of Forking Workflow

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 14. What is git cherry-pick?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 15. What is a "bare git" repository?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 16. When should I use git stash?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 17. You need to rollback to a previous commit and don't care about recent changes. What commands should you use?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 18. What is difference between git stash pop and git stash apply?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 19. What is the HEAD in Git?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 20. How do you make an existing repository bare?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 21. Can you explain what git reset does in plain English?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 22. When would you use git clone over git clone --mirror?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 23. When would you use git clone over git clone --bare?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 24. When would you use git clone --bare over git clone --mirror?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 25. What is the difference between git clone, git clone --bare and git clone --mirror?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 26. What is git bisect? How can you use it to determine the source of a (regression) bug?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 27. How can you use git bisect to determine the source of a (regression) bug?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 28. What are the type of git hooks?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 29. Do you know how to easily undo a git rebase?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 30. What are "git hooks"?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 31. When do you use git rebase instead of git merge?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 32. Write down a sequence of git commands for a "Rebase Workflow"

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 33. How to remove a file from git without removing it from your file system?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 34. How to amend older Git commit?

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 35. Write down a git command to check difference between two commits

πŸ‘‰πŸΌ Check all 36 answers


πŸ”Ή 36. What git command do you need to use to know who changed certain lines in a specific file?

πŸ‘‰πŸΌ Check all 36 answers


About

🟣 Git Interview Questions Answered to help you get ready for your next tech interview.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /