11 Toughest GIT Interview Questions And Answers For Experienced from Codingcompiler. Test your git commands by answering 11 tricky questions on GIT. Recent polls on Stack Overflow show that over 70% of developers use git for open source software and for commercial products. The advantages of this VCS for teamwork are difficult to overestimate. Let’s start learning GIT interview questions and prepare for interviews. All the best for your future and happy learning.
GIT Interview Questions
Here we listed 11 toughest GIT interview questions and answers, let’s explore them.
Question 1. What is the difference between fork, branch and clone?
- Fork – a remote copy of the repository on the server, different from the original. This is not even a git-concept, but rather a political and social idea.
- Clone is not the same as fork. The clone of the remote repository is located locally. In fact, during cloning, all data is copied, including the history of commits and existing branches.
- Branch , or creating a branch, is a way to make changes to a project and eventually merge them with the rest of the code. The branch is part of the repository.
Question 2. What is the difference between pull request and branch?
- Branch is just a separate version of the code.
- Pull request – this attempt to add your own changes to the repository of another owner. To make such a request, you need to take someone’s project, create a separate branch, and then offer to merge it with the rest.
Question 3. Explain the difference between the git pull and git fetch commands?
In simple terms, git pull = git fetch + git merge.
- When you pull , git tries to do all the work automatically for you. This process depends on the context, git will merge all the commits and update the branch you are currently on. Merging is carried out automatically without your participation. If the system detects incomparable differences, a conflict will occur.
- When you do a fetch , git simply collects all the commits of the target branch that you do not already have, and saves them locally. The merging of branches does not occur. This is very useful if you need the current status of the repository, but it can disrupt your work. After reviewing the changes, you can merge them into your thread using merge.
Question 4. How to cancel the previous commit?
Suppose you have the following situation. The pointer
HEADis in C, and (F) is the current state of your files.
You can roll back to the previous state using the git reset command group with different flags.
• To completely cancel a commit, use
git reset --hard HEAD~1
HEADpoints to B. The flag
--harderases all changes to your files to state B.
• To cancel a commit, but save the changes made to it, just run
git reset HEAD~1
So we move
HEADone commit back (B), but leave the files in the state they are in.
git statuswill show that the files match commit C.
• To cancel a commit and save all indexed files, use
git reset --soft HEAD~1
git statusand verify that the git index contains the same files as before.
GIT Interview Questions And Answers
Question 5. What is git cherry-pick?
The command is
git cherry-pick used to transfer individual commits from one repository site to another, usually between development and maintenance branches. This mechanism is different from the usual git merge and git rebase commands that transfer commits in whole chains.
git cherry-pick <commit-hash>
Question 6. Tell us about the benefits of forking workflow.
Working through forks is fundamentally different from other popular methods of organizing team development. Instead of using one server repository as a central code base, here each developer gets his own repository. Most often, this model is used in open source projects.
The main advantage of forking workflow is that all changes are made without pollution of the project history. Developers push into their own repositories, and only the manager has access to the central one.
When the update is ready for integration, the programmer makes a pull request to the main repository, and the manager approves and submits it.
Question 7. What is the difference between HEAD, the working tree and the index?
- A working tree (working directory, workspace) is a tree of source files that you can see and edit.
- An index (staged area) is one large binary .git / index file that lists all the files of the current branch, their SHA1, timestamps, and names. This is not a separate directory with file copies.
- HEAD is a reference to the last commit in the current extracted branch.
Question 8. Tell us about the gitflow-organization of the workflow.
The gitflow model uses two parallel “long” branches to store the project’s history: master and develop.
- Master is a state completely ready to release with all passed tests.
- Hotfix – branches of service, or hotfixes, which are used for quick patches. They are very similar to feature, but instead of develop-branches are based on master.
- Develop is a branch in which all individual developments are combined and tested. After passing the checks, they are sent to the master.
- Feature – a separate branch for each new functionality, changes from which are sent to develop.
Tricky GIT Interview Questions And Answers
Question 9. When should I use git stash?
git stash takes your changes, prepared and unprepared for fixing, saves them for later use and removes from the workspace.
$ git status
On branch master
Changes to be committed:
new file: style.css
Changes not staged for commit:
$ git stash
Saved working directory and index state WIP on master: 5002d47 our new homepage
HEAD is now at 5002d47 our new homepage
$ git status
On branch master
nothing to commit, working tree clean
This is useful in a situation where you suddenly realize that the last commit should be changed, but you have already started another job in the same branch.
$ git stash save
$ git add –u
$ git commit —ammend
$ git stash pop
Question 10. How to delete a file from git, but leave it in the file system of the computer?
If you are not careful with the use of git add commands, you may accidentally add files to the index that should not be there.
git rmcan remove them from the index, but at the same time erase them from the file system (working tree). This is not always what is required.
git reset filename
echo filename >> .gitingore
The team is the
git reset <path>opposite
git add <path>.
Question 11. When should git rebase be used instead of git merge?
The purpose of these git commands is to integrate changes from one branch to another, but they do it differently.
Suppose you have this situation:
A <- B <- C [master]
D <- E [branch]
After the usual merge repository will look like this:
A <- B <- C
D <- E <- F
git rebase– so:
A <- B <- C <- D <- E
Rebase points out that commits need to be literally moved from the old place to the new.
What to choose?
- If in doubt, use the regular merge.
- The choice between merge and rebase is determined by what you want to see the commit history: linear or branching.
Consider the following factors:
- If the branch in which you want to make changes is available for other developers (for example, in an open source project), do not use rebase. This command deletes the entire branch and leads to out of sync copies of the repositories.
- Is the original branch a value? Some commands operate on the principle of “one function – one branch”, and the branch identifies the sequence of commits. In the model “one developer – one branch” there is no special need for this, since the author of the commit is known.
- Do you want to suddenly cancel the merger? A rebase return is significantly more difficult than a normal merge, and sometimes even impossible.
RELATED INTERVIEW QUESTIONS
- Spring Boot Interview Questions
- Network Security Interview Questions
- CheckPoint Interview Questions
- Page Object Model Interview Questions
- Apache Pig Interview Questions
- Python Interview Questions And Answers
- Peoplesoft Integration Broker Interview Questions
- PeopleSoft Application Engine Interview Questions
- RSA enVision Interview Questions
- RSA SecurID Interview Questions
- Archer GRC Interview Questions
- RSA Archer Interview Questions
- Blockchain Interview Questions
- Commvault Interview Questions
- Peoplesoft Admin Interview Questions
- ZooKeeper Interview Questions
- Apache Kafka Interview Questions
- Couchbase Interview Questions
- IBM Bluemix Interview Questions
- Cloud Foundry Interview Questions
- Maven Interview Questions
- VirtualBox Interview Questions
- Laravel Interview Questions
- Logstash Interview Questions
- Elasticsearch Interview Questions
- Kibana Interview Questions
- JBehave Interview Questions
- Openshift Interview Questions
- Kubernetes Interview Questions
- Nagios Interview Questions
- Jenkins Interview Questions
- Chef Interview Questions
- Puppet Interview Questions
- RPA Interview Questions And Answers
- Demandware Interview Questions
- Visual Studio Interview Questions