GIT Interview Questions And Answers For Experienced

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. Updated Interview Questions 2020.

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?

Complexity: 2

  • 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?

Complexity:2

  • 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?

Complexity: 2

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?

Complexity: 3

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

Now 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

Call 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?

Complexity: 3

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.

Complexity: 3

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?

Complexity: 3

  • 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.

Complexity: 3

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?

Complexity: 3

git stash takes your changes, prepared and unprepared for fixing, saves them for later use and removes from the workspace.

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.

Leave a Comment