Git

What is GIT?

GIT is version control system or distributed VCS to use for different projects and programmers to centralize the code of particular project at one place.

What are the advantages of using GIT?

The advantages of using GIT are High availability, data redundancy and replication, only one .git directory per repository, collaboration-friendly, disk utilization, and network performance, any project can be used in GIT (small or large), scalability, easily integrated with other tools like Jenkins etc.

Can you define GIT and repository in GIT?

A GIT repository consists of a directory named .git, in which it keeps all repository data. The content remains private to git. GIT is recommended to use as it can be used for any project without any restrictions.

Difference between GIT and SVN?

GIT is referred to as distributed control version system and SVN is referred as centralized version system.
While working with GIT, the code can be taken once in your local machine and changes can be done and committed, and an end, the whole can be committed in one go to master branch. It means it does not require connected with a network for check in the code all the time. While working with SVN, it needs to be connected with the network when any code needs to be committed.

Mention GIT commands that are mainly used?

Most used commands are:
  • GIT status: To know the comparison between the working directories and index.
  • GIT diff: to know the changes between the commits and the working tree.
  • GIT stash applies: to get the saved changes on the working directory.
  • GIT log: to know specific commit from the history of commits.
  • GIT add: It adds file changes in an existing directory to index.
  • GIT rm: It removes a file from the staging area.
  • GIT init: creating a new repository.
  • GIT clone: to copy or check out the working repository.
  • GIT commit: committing the changes.
  • GIT PUSH: sending the changes to the master branch.
  • GIT pull: fetch the code already in the repository.
  • GIT merge: merge the changes on the remote server to the working directory.
  • Git reset: to reset or drop all the changes and commits.

Can you explain the purpose of branching and its types?

In Git, the branching is done to allow the user to create their own branch and toggle between those branches. It allows the user to switch between the branches to keep the current work in sync without disturbing master branches and other developer’s work as per their requirements. There are 3 types of branching:
  • Feature branching keeps all the changes in the branch and when the feature is completely tested and validated merged into master..
  • Task branching, and Release branching. Feature branching keeps all the changes in the branch and when the feature is completely tested and validated merged into master. Task branching included its own branch with task key included in branch name.
  • Release branching, it develops the branch acquires enough feature for a release the user can clone that branch to form releasing branch.

Can you explain Git stash and Git stash drop?

Git Stash takes the current state of working directory and index. It pushes into the stack for later and returns cleaning the working directory. It helps in instances the work in the project and switches the branches to work. Git stash drop is used when you are done and want to eliminate the stashed item from the list, then running the GIT stash drop command will remove last added stash item by default and can also remove the specific item if any argument is included or mentioned.

What is GIT bisect and its purpose?

GIT bisect command is the command which is used to find that commit which has invoked bug by using binary search. This command uses the binary search algorithm to find the commit, which has a bug and it is referred to as bad commit. Before the bug has been introduced, it was referred to as good commit. This command will search the commit between the endpoints until it finds the exact commit, which introduced the change or bug.

Can you explain head in git?

This is the frequently asked GIT Interview Questions in an interview. Ahead in GIT is referred as commit object. Master is referred to as the default head in every repository. The repository can contain any number of head.

Explain SubGit and its use?

SubGit is a tool for smooth, stress-free SVN to GIT migration. It is a solution for company-wide migration from SVN to GIT. It is better than git-svn, no requirement to change the infrastructure that is already placed allows using all git and svn features, and provides genuine free migration experience.

How to rebase master in GIT?

Rebasing is defined as the process of moving a branch to a new base commit. The rule of git rebase is to never use it on public branches. To synchronize two branches is to merge them together, which results in extra merge commit and two sets of commits will contain the same changes.