In this article, I am going to cover few basic questions related to Git that every developer should know. There are more but i am just trying to cover few very common questions:

  1. Difference between Git vs SVN

The main point in Git vs SVN debate boils down to this: Git is a distributed version control system (DVCS), whereas SVN is a centralized version control system.

2. What is Git fork? What is difference between fork and branch? How to create tag?

A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.

A fork is really a Github (not Git) construct to store a clone of the repo in your user account. As a clone, it will contain all the branches in the main repo at the time you made the fork.

Create Tag:

  • Click the releases link on our repository page.
  • Click on Create a new release or Draft a new release.
  • Fill out the form fields, then click Publish release at the bottom.
  • After you create your tag on GitHub, you might want to fetch it into your local repository too: git fetch.

3. What is git cherry-pick?

Cherry picking in git means to choose a commit from one branch and apply it onto another.

This is in contrast with other ways such as merge and rebase which normally applies many commits onto a another branch.

Make sure you are on the branch you want apply the commit to. git checkout master Execute the following:

git cherry-pick <commit-hash>

4. How to revert previous commit in git?

To revert to a previous commit, ignoring any changes:

git reset — hard HEAD

where HEAD is the last commit in your current branch

5. How to rebase master in git? Difference between rebase and merge. How to squash or fixup commits?

Rebasing is the process of moving a branch to a new base commit.

The golden rule of git rebase is to never use it on public branches. … The only way to synchronize the two master branches is to merge them back together, resulting in an extra merge commit and two sets of commits that contain the same changes.

6. Explain git stash, pop

Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.

git stash pop applies the top stashed element and removes it from the stack. git stash apply does the same, but leaves it in the stash stack.

7. Branching strategies Pros and Cons — Feature, Release branching, Git flow, Lean Git flow

Pro: By keeping latest deployed version in trunk, small fixes can be rolled out quickly without extensive testing of the latest development version.

Pro: Developers can work more freely in tighter iterations without stepping on eachother’s feet.

Pro: if you have many branches you’ll be pushed to adopt a modern DVCS (my experience is with Mercurial but I hear git or Bazaar are also good) rather than stay with a traditional centralized system (like, say, svn).

Pro: Branches can be used to facilitate ‘what-if’ scenario’s in trying out new code. At the end a decision can be made to merge the new feature or to abandon it.

Con: Having too many branches in the air at the same time and you start forgetting where things where commited, where changes have been made etc.

Con: someone has to manage the branch(es) and keep on top of things. In most teams this falls by the way-side.

8. What is GIT?

GIT is a distributed version control system and source code management (SCM) system.

9. What is ‘head’ in git and how many heads can be created in a repository?

A ‘head’ is simply a reference to a commit object. In every repository, there is a default head referred as “Master”. A repository can contain any number of heads.

10. What are Git repository hosting services you used?

Github, Bitbucket, Gitlab or you can specify if you have used something else here.

11. What is the function of ‘git reset’?

‘Git Reset’ is to reset your index as well as the working directory to the state of your last commit.

12. What is the syntax for “Rebasing” in Git?

Syntax: “git rebase [new-commit] “

13. What is a ‘conflict’ in git?

A ‘conflict’ arises when the commit that has to be merged has some change in one place, and the current commit also has a change at the same place.

14. What language is used in Git?

Git used “C programing language”.

15. What Are The Advantages Of Using Git?

a) Data redundancy and replication
b) High availability
c) Only one.git directory per repository
d) Superior disk utilization and network performance
e) Collaboration friendly
f) Any sort of projects can use GIT

Hope this post will help you to crack your interview. As always credit for this post goes to multiple blogger and QnA websites.

--

--