Here are some of the frequently asked questions about GIT in job interviews.
In interviews, you will be asked for various git commands that I have already explained in the git tutorial. Go through it.
Now let’s start with some of the Git questions for experienced candidates usually asked in the job interviews.
Table of Contents
Answer: Refer to this Git Lifecycle diagram. This will give answers to many of the git questions.
It is expected from you to explain all four stages (local directory, staging area, local repo and remote repo) along with basic git commands. I have explained everything in our git tutorial.
Explain how the transition happens starting from modifying code to pushing it to the remote repo using git commands.
Here the remote repo is hosted on the code repository services like GitHub, Bit Bucket, Git Lab and many others.
Answer: It is the short name given the original remote repository from where the code is cloned.
When you run the clone command, you have to mention the remote repository URL as a parameter. This URL parameter becomes origin.
Now next time, whenever you want to use remote repo URL (Especially, in push command, you need remote repo URL. ), you don’t need to mention the complete URL. Instead of that, you can mention “origin”.
Answer: Usually, one local branch is used to work on one feature or defect. Git provides a provision to work on multiple features or defects by creating multiple branches.
You can switch the branch with the git checkout command.
git checkout <branch-name-you-want-to-switch-to>
Answer: Use the git branch command.
It will list out all the local branches.
Answer: Use diff command to see check the differences between files in the local directory and files in the staging area.
git diff --color
Git diff command shows us uncommitted changes since the last commit.
Use –color option to check the difference so that output will be colorized and more visual.
You can see the different colors for the words that are changed.
Note: You will not see the difference if all the modified files are committed to the local repository.
Answer: You can use the git show command to check the metadata and content changes of the specific commit.
git show --color
The –color is an optimal parameter to see the output in different colors.
Answer: Yes, you can do that. While configuring username, use —local option.
git config --local user.name "<Your_Name>"
Answer: It has several advantages over a centralized server model like SVN.
Answer: Basically git pull is the combination of two command- git fetch and git merge.
When you run git fetch command, it fetches the recent commit into the local repository. After that, git merge command merges changes to the local directory.
If you want to pull the changes from the remote repo and merge it into the local directory, it easy to convenient to use git pull command, instead of executing two different commands.
Answer: Sometime, unknowingly we pushed the wrong changes to the git repo or whatever we have pushed earlier may not require now.
In that case, you can undo the changes using the git revert command. Check the steps to revert the Git changes. It is just two steps process.
These are the GIT interview questions and answers. If there is anything you want to ask, feel free to write in the comment. If you find these questions useful, comment your thought.
I will keep adding more questions to this list in the coming day. Stay tuned!