21 Git Command Concepts Interview Questions and Answers for Software Developers and DevOps Engineers
2. What is the difference between reverting and resetting? git revert vs git reset
Answer:
Git reset is a powerful command that is used to undo local changes to the state of a Git repository. Git reset operates on “The Three Trees of Git” which are, Commit History (HEAD), the Staging Index, and the Working Directory.
On the other hand, Revert command in Git creates a new commit that undoes the changes from the previous commit. This command adds a new history to the project. It does not modify the existing history.
For this reason, git revert should be used to undo changes on a public branch, and git reset should be reserved for undoing changes on a private branch.
3. What is the difference between git pull and git fetch?
Answer: Git pull command pulls new changes or commits from a particular branch from your central repository and updates your target branch in your local repository. On the other hand, git fetch is also used for the same purpose but it works in a slightly different way.
When you perform a git fetch, it pulls all new commits from the desired branch and stores it in a new branch in your local repository. If you want to reflect these changes in your target branch, git fetch must be followed with a git merge. Your target branch will only be updated after merging the target branch and fetched branch.
4. How do you resolve conflicts in Git?
Answer: This is one of the really important question and often asked to experienced developers. If multiple people are modifying same file and pushing their changes then there are chances of conflict. In that case you cannot merge your PR and you have to resolve conflicts.
Here are the steps that will help you resolve conflicts in Git:
- Identify the files responsible for the conflicts.
- Implement the desired changes to the files
- Add the files using the git add command.
- The last step is to commit the changes in the file with the help of the git commit command.
5. What is the difference between ‘git remote’ and ‘git clone’?
Answer: ‘git remote add’ creates an entry in your git config that specifies a name for a particular URL whereas ‘git clone’ creates a new git repository by copying an existing one located at the URL
6. What is Git?
Answer: Git is a version control system for tracking changes in computer files and is used to help coordinate work among several people on a project while tracking progress over time. In other words, we can say it’s a tool that facilitates source code management in software development.
7. What is a Git repository?
Answer: Git
repository refers to a place where all the Git files are stored. These
files can either be stored on the local repository or on the remote
repository. If you remember, Git is a distributed version control
system, which means you can have your repo in your local machine and it
also contain all the version of your file. When you push the changes to
remote repository, it will be transferred to server and stored there as
well.
8. What are some of the best graphical GIT client for LINUX?
Answer: Some of the best GIT client for LINUX are:
- Git Cola
- Git-g
- Smart git
- Giggle
- Git GUI
9. What are basic Git commands with their functions?
Answer:
- Git config - Configure the username and email address
- Git add - Add one or more files to the staging area
- Git diff - View the changes made to the file
- Git init - Initialize an empty Git repository
- Git commit - Commit changes to the head but not to the remote repository
If you need more here is a nice list of essential git commands:
10. What are the advantages of using Git?
Answer: While there are many advantages of using Git for version control and code repository here are a couple of key advantages I remember top of my head
- Faster release cycles
- Easy team collaboration
- Widespread acceptance
- Maintains the integrity of source code
- Pull requests and code review
11. How can you discover if a branch has already been merged or not?
Answer: There are two commands to determine these two
different things.
- git branch --merged - Returns the list of branches that have been merged into the current branch.
- git branch --no-merged - Returns the list of branches that have not been merged.
12. What are the various Git repository hosting functions?
Answer:
- Github
- Gitlab
- Bitbucket
- SourceForge
- GitEnterprise
13. What does a commit object contain?
Answer:
Commit object contains the following components:
- A set of files, representing the state of a project at a given point of time
- Reference to parent commit objects
- An SHA-1 name, a 40 character string that uniquely identifies the commit object
14. What is SubGit?
Answer: SubGit is a tool
for SVN to Git migration. It can create a writable Git mirror of a local
or remote Subversion repository and use both Subversion and Git as long
as you like.
15. What language is used in Git?
Answer: Git
uses ‘C’ language. GIT is fast, and ‘C’ language makes this possible by
reducing the overhead of run times associated with high-level languages.
16. What are some of the most popular Git repository hosting
functions?
Answer: Below is the list of Git repository hosting
functions:
- Pikacode
- Assembla
- Visual Studio Online
- GitHub
- GitEnterprise
- Net
- Beanstalk
- CloudForge
- GitLab
- Planio
- Perforce
- Fog Creek Kiln
17. What are some of the few Git repository hosting services?
Answer:
- Pikacode
- Visual Studio Online
- GitHub
- GitEnterprise
- SourceForge.net
18. What does ‘hooks’ comprise of in Git?
Answer: This directory consists of shell scripts that are activated if you
run the corresponding Git commands. For example, git will try to execute
the post-commit script after you have run a commit.
19. What is the difference between Git and GitHub?
Answer: Git is a version control system that is used in the management of the
source code history. GitHub, on the other hand, is a cloud-based hosting
service that is used in the management of Git repositories. GitHub is
designed to help in the better management of open-source projects.
20. What is the syntax for rebasing in Git?
Answer: The syntax for rebasing in Git is “git rebase [new-commit]”
21. What is the function of ‘git reset’?
Answer: The function of ‘Git Reset’ is to reset your index as well as the
working directory to the state of your last commit.
That's all about the
frequently asked Git interview questions and answers. Every
programmer and software developer should know essential git concepts
like remote repository, push, pull, fetch, squashing commits, rebase etc
and those are the ones which are often asked during interviews.
In summary, the above-mentioned questions, are the most suitable ones because they are the ones that are frequently asked in Git interviews. You will find nothing strange when you enter the interview room and therefore you just have to relax and think about the questions with answers that you have gone through above. I wish you the best of luck in your forthcoming interview.
- 20 Software Design and Pattern Questions from Interviews
- 40+ Object-Oriented Programming Questions with Answers
- 17 Spring AOP Interview Questions with Answers
- 25+ Spring Security Interview Questions with Answers
- 50+ Microsoft SQL Server Phone Interview questions
- 17 Java Debugging Interview Questions with Answers
- 10 Oracle Interview Questions with Answers
- 30 JavaScript Interview Questions with Answers
- 12 SQL Query Interview questions with solutions
- 10 Java Locking and Multithreading questions
- 25 Recursion Interview questions with answers
- 130+ Java Interview Questions with Answers
- 20 Algorithms Interview Questions for Software Developers
- 20+ Spring Boot Interview Questions with Answers
- 20 JUnit Interview Questions with Answers
- 50 SQL and Database Interview Questions for Beginners
- 20 PostgreSQL Interview Questions with Answers
- 15 Cyber Security Interview Questions with Answers
- 35 Python Interview Questions for 1 to 2 years experienced
I miss one Git question I always ask in interviews:
ReplyDelete"What is the difference between merge and rebase?"
Where drawing the answer visually on a white board is an extra plus!
This is a good question, knowing the difference is vital, especially in team projects - you don't want developers overwriting each other's commits