There are a lot of different questions which needs to be prepared for the interview as it depends on the level of the candidate also. As there is approx 70 per cent of users uses git in day to day life.
We will try to accumulate the levels in different segments as:
- 0 - 1 Year as Level Low
- 1 - 3 Years as Level Medium
- 3 Years and so on as Level High
Let's Start with Questions and Answers:
Q: What is git stash?
Level: Low
A: It keeps your uncommitted both staged and unstaged changes on your local repo for later use with a tag. You can simply push and pop on the stash to put changes and pull changes.
Q: What is git stash?
Level: Low
A: It keeps your uncommitted both staged and unstaged changes on your local repo for later use with a tag. You can simply push and pop on the stash to put changes and pull changes.
git stash
git stash pop
Q: What is Git Fork?
Level: Medium
A: It is a copy of the repository which is stored at the server side or at the remote. It is distinct from the original data.
Git Fork Explanation |
Image from here
Level: Medium
A: Clone is a local copy of the original data at your system which is the reference of the remote repository. When you clone any remote repository you are actually copying the data present at your destination location.
Q: What is Git Branch?
Level: Medium
A: Branch is a mechanism to differentiate changes in the repository under tags. Conceptually it represents the thread of development.
Q: What is the pull request?
Level: Medium
A: When you make branch on the repository and make changes to the code. Once you are ready to merge the code to the repository with a master or any other branch. This will take the code that has been written from one branch to another branch.
Q: What is the difference between git pull and git fetch?
Level: Medium
A: Git Pull: In simple terms, it does a git fetch followed by git merge
Git Fetch: Git gathers commits from the target branch and stores to local repository. It won't merge the data fetched from the repo to your current branch. This is very useful when you are working on something which might break by the merge of the latest code fetched from the target branch.
Q: How to revert the previous commit in the git?
Level: High
A: To delete the changes in the commit
git reset --hard HEAD~1
Q: What is git cherry-pick?
Level: High
A: It is used to introduce a few commits from one branch within repo to another branch.
git cherry-pick <commit-hash>Q: How you will remove the file from git but not from your system?
Level: High
A: By using git reset <filename>, As git rm will remove it from the git and filesystem as well
git reset <filename>Watch the video to know more:
Keep Learning and Keep Smiling :)