GIT Interview Questions and Answers

Last updated on 04th Oct 2020, Blog, Interview Question

About author

Ramya (Sr Technical Director )

Highly Expertise in Respective Industry Domain with 6+ Years of Experience Also, She is a Technical Blog Writer for Past 2 Years to Renders A Kind Of Informative Knowledge for JOB Seeker

(5.0) | 14536 Ratings 1682

This informative tutorial includes a set of the most likely asked questions in Git interviews along with their descriptive answers. These questions will certainly help you prepare for and crack any Git interview successfully.

Whether you are a novice or an experienced professional, these interview questions on Git and detailed answers will definitely help you enrich your knowledge of the subject and excel at your work as well as interviews.

1.What is Git?

Ans:

Git is a distributed version control system (DVCS) and Source Code Management System (SCMS) that helps in tracking changes to a file. The functionality of Git allows developers to revert back to any specific change. Git can also help in the management of small and large projects with higher speed and efficiency. The distributed architecture of Git is the primary reason for its superiority in comparison to other version control systems. The most notable feature of Git is that it does not depend on a central server for storing all versions of the files in a project. 

2. Are Git and GitHub different?

Ans:

Git is a version control system for tracking modifications in source code over the course of software development. On the other hand, GitHub is the repository hosting service for Git. GitHub also provides additional features on its own. Some of the important features in GitHub include access control and collaboration features. In addition, GitHub also provides simple task management tools for different projects. 

3. What are the benefits of using Git?

Ans:

Here are the most noticeable benefits of Git. 

  • Any project could utilize Git without any restrictions 
  • Git supports collaboration
  • Higher availability alongside functionality of data redundancy and replication
  • Better disk utilization and network performance
  • The facility of only one Git directory for every repository

4. What language does Git use?

Ans:

Git uses C language for the reduction of overheads with run times that are common in high-level languages. 

5. What is a repository in Git, and how can you create one?

Ans:

Repository in Git is the place that Git uses for storing all files. Git stores the files in the local repository or in the remote repository. The process to create a repository in Git is one of the most commonly asked questions. First of all, you have to create a directory for the project for creating a repository. Then, you can run the command “git init” and create a git repository in the project directory. 

6. What is a bare repository?

Ans:

A bare repository contains information regarding version control. The bare repository does not contain any working files or the special.git sub-directory. On the contrary, the bare repository contains all information of the .git subdirectory in the main directory directly. The working directory contains the working tree, i.e., verified copies of project files and .git subdirectory with all Git related revision history for your repository. 

7. How is Git different from SVN?

Ans:

First of all, Git does not have adequate functionality for managing excessively large files or frequently fluctuating binary files. On the other hand, SVN can manage multiple projects in the same repository.

The second point of difference is in the fact that Got lacks support for commits across multiple branches or tags. On the contrary, SVN or Subversion supports the creation of folders irrespective of the location in the repository layout. Modifications in Gits are impossible. However, Subversion provides flexibility to committers for treating a tag as a branch and creating multiple revisions in a tag root. However, the distributed Git is better than the centralized SVN. 

8. What is Git Commit, and what are the contents of the commit object?

Ans:

The Git commit is a command executed during a project for recording the progress of the project. The commit object contains a set of files representing the state of a file at different instances of time. The commit object also consists of a reference to the parent commit. Finally, you can also find an SHAI name, a unique identifier with a 40-character string for the commit object. 

9. What are the different Git repository hosting functions?

Ans:

Apart from GitHub, the other prominent Git repository hosting functions include

  1. 1. Gitlab
  2. 2. Bitbucket
  3. 3. GitEnterprise
  4. 4. SourceForge

10. What is the conflict in Git?

Ans:

Git could handle the majority of merges on its own by leveraging its automatic features. Conflict is evident when two different branches make edits to the same line in a file. Another scenario for conflict in Git occurs with the deletion of a file on one branch and modification of the same file in another branch. Conflicts are general occurrences, especially when functioning in a team environment. 

Subscribe For Free Demo

Error: Contact form not found.

11. What is the process of resolving conflicts in Git?

Ans:

Here are the steps for resolving conflicts in Git.

  • Recognize the files responsible for the conflict
  • Implement necessary changes to the files for avoiding any possibilities of conflict
  • Add the files by using the command “git add.”
  • The final step involves committing the changed file through the command “git commit.”

12. What is branching, and how many types of branching are there in Git?

Ans:

Branching in Git is a helpful tool for supporting users in the creation of their personal branch and switch between the branches. Users can revert back to their old work without any compromises with the existing work. The different types of branching in Git are feature branching, task branching, and release branching. Feature branching involves keeping all changes of a particular feature in a branch.

After complete testing and validation of a feature, feature branching involves merging of the feature in the master. Task branching involves the inclusion of the new feature in the own branch along with including task key in the branch name. Release branching involves the formation of a clone of a branch in cases where a developed branch includes sufficient features for a release. 

13. What is SubGit?

Ans:

SubGit is a tool for migrating from SVN to Git. SubGit can help in the creation of a writable Git mirror of a local or remote Subversion repository. It can use Subversion as well as Git for any duration the user needs. SubGit also provides faster one-time import from Subversion to Git. In addition, you can use SubGit within the Atlassian Bitbucket server. SubGit does not demand any changes in existing infrastructure. Furthermore, SubGit also offers flexibility for using all features of Git and Subversion. 

14. What are the uses of git instaweb?

Ans:

The “git instaweb” command helps in automatically directing a web browser and running a web server with an interface to the local repository. 

15. What are the common Git commands and their uses?

Ans:

Here are some of the common Git commands, along with their functions.

  1. 1. “git diff” helps in showing changes between commits and those between commits and working trees.
  2. 2. “git status” helps in showing differences between the index and working directories
  3. 3. “git stash applies” is the command for bringing back saved changes on the working directory
  4. 4. “git log” helps in finding a specific commit in the history
  5. 5. “git checkout” is the command for updating directories of the working tree with directories from another branch without merging
  6. 6. “git rm” helps in removing files from staging area and files on the disk
  7. 7. “git add” helps in adding file modifications in the current directory to the index
  8. 8. “git reset” command helps in resetting the index. It also helps in resetting working directory to the state of the last commit
  9. 9. “git is a tree” is ideal for the representation of a tree object alongside the mode and name for each item

16. What is the difference between clone, fork, and branch on Git?

Ans:

A Git fork is a remote, server-side replica of a repository, different from the original. It is evident to note that a fork is not a Git concept and is a social paradigm. Clone in Git is a local copy of a particular remote repository. During the process of cloning, users copy the entire source repository information alongside all the branches and history. The branch is a process for the management of all changes in a single repository before merging them into the code. You can consider a branch as a thread of the development project that exists within a repository. 

17. How is a “branch” different from a “pull request”?

Ans:

The branch is merely a separate version of the code. A pull request becomes evident when an individual takes the repository, makes it their own branch, makes modifications, and then attempts merging that branch in another code repository. 

18. Do you know the use of “git cherry-pick”?

Ans:

The use of the “git cherry-pick” command is evident in the processes for the introduction of specific commits from a branch in a repository to another branch. The common application of “git cherry-pick” is evident in forward- or back-port of commits from a maintenance branch to a development branch. This approach is different from other approaches such as merge and rebase that generally apply various commits to another branch. 

19. What is the staging area in Git?

Ans:

The staging area is an intermediate area that helps in formatting and reviewing commits before their completion. It is also known as an index. The staging area is the first place for verification of every change before committing to the repository. 

20. Is it reasonable to create an additional commit or modify an existing commit?

Ans:

You need to be clear that the creation of an additional commit is favorable as compared to modifying an existing commit. Modifications can destroy the previously saved state in the commit. Amendments in the content of the commit can lead to probabilities for the elimination of crucial data. Excessive use of “git commit- amend” can lead to the growth of a small commit and accumulation of unwanted changes.

21. What is the difference between the head, working tree, and index in Git?

Ans:

The working tree is also known as the working directory or the workspace. It is the directory tree of source files that a user sees and edits. The index or the staging area is just a single, binary file in the <baseOfRepo>/.git/Index. The index contains a list of all files in the existing branch, the SHA1 checksums, file name, and time stamps. The “HEAD” implies a reference to the last commit in the existing checked-out branch.

22. What is the use of “git config”?

Ans:

Git leverages your username for associating commits with a particular identity. The ‘git config’ command helps in changing Git configuration as well as your username. For example, if you want to have a username and email id for associating a commit with a particular identity, then you can use the following commands. 

  • git config -global user. Name “Name”                 //can add a username
  • git config -global user.email “E-mail Address”    //will add an email ID

23. What is git stash?

Ans:

Working on a specific project involves a lot of mess and requirements for switching branches. Stashing on Git helps in taking your working directory with modified tracked files and staged modifications and storing them on a stack of unfinished changes. Users could reapply the changes at any time according to their preferences. 

24. What type of work can you restore with the recovery of a deleted branch?

Ans:

Upon recovery of a deleted file, you can recover the stashed or saved files in the stashed index. Untracked files are not recoverable. The recommended best practice is to stage and commit your work in all cases or ensure their stashing. 

25. How is ‘git diff’ different from ‘git status’?

Ans:

‘git diff’ helps in representing the changes between commits and the changes between commits and working tree. On the other hand, ‘git status’ helps in finding the difference between the working directory and the index. As a result, it helps in understanding a particular git in detail. The prominent difference is that “git diff” shows differences between various commits, while “git status” does not.

26. How can I know if a branch is already merged into master?

Ans:

The following commands can help in finding whether a branch has been merged in the master or not. 

To list out branches merged in the current branch, use

  • git branch –merged

To list out branches not merged in the existing branch, use

  • git branch –no -merged

27. What are the contents of ‘hooks’ in Git?

Ans:

The “hooks” directory includes shell scripts that activate upon running the related Git commands. For instance, git would attempt the execution of a post-commit script after running a commit. 

28. How can I find a list of files changed in a specific commit?

Ans:

The Ans is quite simple! Just use the command

  • git diff-tree -r {hash}

The ‘-r’ flag helps in listing the individual files. The output can contain some additional information. However, you can downplay the extra information with the help of two additional flags. The command with the additional flags would be

  • git diff-tree –no-commit-id –name-only -r {hash}

The –no-commit-id helps in suppressing the commit hashes from the output. The “–name-only” flag helps in printing the file names rather than the paths. 

29. How can I remove a file from git without removal from the file system?

Ans:

“git rm” can help in removing files from the staging area as well as the file system or working tree. However, the application of “git rm” cannot be valid in all cases.

Syntax:

  • git rm filename

Therefore, you should use the “git reset” command with the syntax like,

  • git reset filename

You can also use the command,

  • echo filename >> .gitignore

and add it to .gitignore library for avoiding re-additions. 

30. What are the differences between rebase and merge in Git?

Ans:

The rebase command in Git helps in the integration of changes from one branch to another. You can use it instead of the merge command. The merge command helps in taking independent lines of development in the git branch and integrating them in a single branch. The difference between the two commands is evident in the fact that rebases have to rewrite commit history for producing straight, linear order of commits. 

31. What is the difference between reverting and resetting?

Ans:

The reset command in git helps in reverting local changes to the state of a Git repository. “git reset” works on commit history, the working directory, and the staging area. The revert command in git helps in the creation of a new commit that negates the changes from the previous commit. The revert command helps in adding a new history to the project without modifying existing history. 

32. How can you return a commit that has been pushed and made open?

Ans:

“git revert” can help in reverting one or multiple commits. The command helps in the creation of a new commit that cancels out changes brought in the previous commits. The following command can help in reverting the two previous commits.

  • git revert HEAD~2.HEAD

33. What are the benefits of forking workflow?

Ans:

The first difference is that forming workflows does not use a single server-side as the “central” codebase. Every developer gets a personal server-side repository. Therefore, forking workflow is common in public open-source projects. Another advantage is the integration of contributions without the need for pushing to one particular central repository. Only the project manager can push to the official repository. Developers can let the project manager know that an update is ready for integration through a pull request. 

Course Curriculum

Best Hands-on Practical Git Training By Top-Rated Instructors

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

34. What is the difference between ‘git fetch’ and ‘git pull’?

Ans:

‘git fetches’ downloads only new data from remote repositories. It does not ensure integration of downloaded data in your working files. ‘git pull’ is ideal for downloading as well as merging data from the remote repository in the local working files. 

35. What is the syntax for rebasing in Git?

Ans:

The syntax for rebasing in Git is,

  • git rebase [new-commit]

36. What is the use of ‘git bisect’?

Ans:

The ‘git bisect’ is an important Git command for finding the command responsible for introducing a bug. The command uses a binary search algorithm for finding the commit in the project history that is responsible for introducing a bug. 

  • git bisect

37. What is the Git stash drop?

Ans:

Git stash drop is the command that helps in removing the list after completing work on the stashed item. As a result, it ensures the removal of any particular item or last added items from the argument. 

38. What are some of the best graphical Git clients for LINUX?

Ans:

The best Git client for Linux is as follows –

  • Git GUI
  • Giggle
  • Git Cola
  • Smart Git
  • qGit
  • Git-g

39. What is git pull origin?

Ans:

The ‘git pull origin master’ command obtains commits from the master branch of the origin that could be the local origin or master branch. Then, it merges the origin or master into the currently checked out branch.

40. What benefits do SCM tools offer with Git?

Ans:

Users could avail exceptional benefits with SCM tools such as CVS, Subversion, ClearCase, and Perforce. The features such as convenient staging areas, multiple workflows, and cost-effective local branching validate the benefits of SCM tools.

41. What is the process for squashing the last N commits to a single commit?

Ans:

This entry is one of the advanced Git interview questions with two distinct responses depending on the context. In case of writing a new commit message from the start, you can utilize the following command. 

  • git reset -soft HEAD~N && git commit

If you have to edit a new commit message with the addition of existing commit messages, then you should extract the messages and pass them to Git commit. The following command helps in achieving the above-mentioned function.

  • git reset -soft HEAD~N && git commit -edit -m“$(git log -format=%B -reverse .HEAD@{N})

42. How should I configure a Git repository for running code sanity checking tools?

Ans:

Sanity checking helps in determining the possibility and feasibility of continuous testing. A sanity test is possible through a simple script that relates to the pre-commit hook of the concerned repository. The script also helps in running other tools such as linters and execute sanity checks for changes committed to the repository. 

43. What is git reflog?

Ans:

“git reflog” command helps in tracking all the changes made in the references of a repository. It maintains a log history of locally created or checked out references to repositories. 

44. How can I cherry-pick a merge commit?

Ans:

Cherry-pick uses a diff for finding out the difference between branches. With the merge commit for a different branch, it has two changesets and two parents.

For instance, if you have merge commit ref 64cv89d, you have to specify -m and use parent 1 as a base as follows –

  • git checkout release-branch  
  • git cherry-pick -m 1 64cv89d

45. How can I copy a commit in one branch to another?

Ans:

The ‘cherry-pick’ command is the best option in this case. It helps in finding the feasibility of reverting back an existing commit to the existing branch or location. Therefore, you have to switch to the target branch and then call the command,

  • git cherry-pick {hash of that commit}

As a result, you can find a new commit with a new hash because of the application of changes to a different destination.

46. What if one of my teammates accidentally deleted a branch and pushed the changes to the central git repo and I want to recover the branch?

Ans:

You need to review the latest commit to the particular branch with reflog. Then, you can check it out as a new branch.

47. What is the Gitflow workflow?

Ans:

Gitflow workflow uses two long-running parallel branches known as master and develop. The components in Gitflow workflow are as follows.

  • The master branch is always ready for live release with everything production-ready.
  • The Hotflix branches help in quick patching of production releases. 
  • The Develop branch helps in merging of all feature branches and also performs all the tests. 
  • The Feature branch implies a unique branch for every new feature. The feature branch could be pushed to the development branch just like their parent branch. 

48. How is ‘git remote’ different from ‘git clone’?

Ans:

‘git remote’ helps in the creation of an entry in the git config while specifying a name for a specific URL. On the other hand, ‘git clone’ helps in the creation of a new git repository through copying an existing repository in the URL.

49. What is the command for fixing a broken commit?

Ans:

For fixing a broken commit, you can use the command,

  • git commit –amend

This command can help in fixing the broken commit message in the editor.

50. What is the general branching pattern in Git?

Ans:

The most general approach for the creation of branches in Git is the development of one “Main” branch. It also involves the creation of another branch for implementing new features. The pattern is helpful in cases where multiple developers work on a single project.

51. How do you define a ‘conflict’ in git?

Ans:

If you want to merge a commit there is a change in one place and the same change already exists then while merging the Git will not be able to predict which is the change that needs to be taken precedence.

52. Explain the basic workflow of GIT.

Ans:

The basic workflow of GIT can be divided into three steps. They are:

  1. 1. User can alter a file from the current directory
  2. 2. User can add those files into the staging area
  3. 3. Users can do commit operations. Commit transfers files from staging. A ‘Push’ saves the changes in the GIT repository permanently.

53. What do you mean by ‘blobs’?

Ans:

Blob refers to a Binary Large Object.  In GIT, every version of a file is called a blob. Generally, a blob will contain file data whereas it will not store any metadata about a particular file. Simply, blob is a binary file. In the DB of Git, blob is named as SHA1(Secured hash function. hash of that particular file. Generally, GIT won’t address its files by names whereas they are content addressed.

Course Curriculum

Learn In-Depth Knowledge on Git Course to Get Best JOBs in Top MNCs

Weekday / Weekend BatchesSee Batch Details

54. What is a tree in GIT?

Ans:

Tree refers to an object which means a directory. Tree keeps blobs and sub directories in it. A tree is nothing but a binary file which saves the references of blobs. A tree is a SHA1 hash of tree objects.

55. Explain commit in GIT.

Ans:

Commit keeps the working state of the repository. A commit can also be named by the secure hash function, SHA1. A commit object can be considered as a node of the linked list. Each of this commit objects will contain a pointer to the parent commit object. To track the history of a commit object, we can look into the parent pointer to get the same. If a commit object contains several parent commits, that commit can be built by combining two branches together.

56. What do you mean by branches in GIT?

Ans:

Branches were meant to build yet another line of development.  Git contains a master branch by default similar to trunk in subversion. Generally, branches were built to work on something new. Once the mean work is completed, that particular branch is merged to the master branch and that particular branch is deleted. Further, each branch is referenced by Head, which is a pointer that points to the current commit in the branch. If a user makes a commit, Head is upgraded with the current commit.

57. What is the purpose of Tags?

Ans:

The purpose of tags is to allocate some meaningful name with a particular version present in the repository. Tags and branches look alike, but tags are permanent. So, tag is a branch but no one can make changes to it. If a user builds a tag for a specific commit, though he creates yet another commit, the same will not be updated. Developers generally build tags for product releases.

58. Explain Clone operation in GIT.

Ans:

The purpose of clone operation is to build a specimen or a mirror of the repository. Clone verifies the current working copy and also creates a mirror of the entire repository. It allows users to perform various functions in the local repository. All these operations can be performed offline without even a network connection. But, if the user needs to sync the repository specimens, a network connection is required to perform synchronization.

59. Explain Push operation in GIT.

Ans:

A ‘push’ copy the changes made from a local repository instance into a remote repository. This saves the changes into the Git repository permanently. A Push operation is similar to a commit operation in subversion.

60. Explain Pull operation in GIT.

Ans:

A ‘pull’ copy the changes made from a remote repository to a local repository. Generally, if we need to synchronize between two repository instances, pull operation can be performed. A Pull operation is similar to an update in the subversion.

61. What do you mean by ‘Head’?

Ans:

Head refers to a pointer which points to the current commit in the branch. If a user makes a commit, Head is upgraded with the current commit.

62. What’s the difference between a “pull request” and a “branch”?

Ans:

A branch is just a separate version of the code.

A pull request is when someone takes the repository, makes their own branch, does some changes, then tries to merge that branch in (put their changes in the other person’s code repository).

63. What do you mean by revision in Git?

Ans:

Revision refers to the version of the source code which is written by a developer. Generally revisions in Git amount to commits. Users can identify the commits through the SHA1 secure hashes.

64. What is an URL in the Git?

Ans:

URL in Git is used to save the config file and it represents the place where the Git repository is located.

65. What is git config in Git?

Ans:

Git supports a tool to set configuration variables, called a git config tool. All the global configurations in .gitconfig file present in the current working directory or home directory is stored by Git. But, the user has to set the variables as global otherwise, by default it is stored in the local directory. For that, the user has to set the configuration parameters to global by adding the –global option.

66. How do you install a Git client in a machine?

Ans:

The installation of Git client varies according to the corresponding linux platform you are using. The syntax varies between various linux platforms. For an instance, if the user uses RPM based Linux/GNU distribution, use yum command :

  • yum –y install git-core

If the user uses Debian based Linux/GNU distribution, use apt-get command as follows:

  • sudo apt-get install git-core

To identify the git version, you can check using:

  • git –version

67. What is the first step to establish connection to Git?

Ans:

Like every setup, initialization is the first step to establish connection to Git. Once you finish the initialization of git, do push/pull source code. The command to initialize Git is:

  • $git init

68. What is the command to get the source code from Github?

Ans:

The command is:

  • $git remote add origin git url
  • $git pull origin repository name

69. What is the command to clone a github repository?

Ans:

The command is:

  • git clone url  project-name/foldername  -b develop

70. What do you mean by git bash?

Ans:

Git bash us a source controller which is used to save the source code developed by the developer.

Git Sample Resumes! Download & Edit, Get Noticed by Top Employers!

71. What is the command to check git status?

Ans:

The following is the command to check git status:

  • $git status

72. What is the command to make commits?

Ans:

The command to make commit is :

  • $git commit -b “Commit description

This command will commit the files.

73. How will you push the committed source code to the server?

Ans:

The command to push the committed source code to server is:

  • git push -u origin master

74. State a way to create a new branch in Git?

Ans:

If you want to create a new feature into the main branch then you can use the command ‘git merge’ or ‘git pull’

  • git merge

OR

  • git pull

75. What is the use of Git instaweb?

Ans:

Git instaweb lets a web browser automatically and runs the web server through an interface to the user’s local repository.

git Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

76. Explain the life cycle of Git.

Ans:

The life cycle of Git contains the following stages:

  • User has to clone the Git repository as a current/working copy.
  • Users can alter the current/working copy by editing/adding files.
  • It is also possible to consider changes from other developers and the same can be updated.
  • Before committing, the user has to review the changes performed.
  • After review, commit. Later push the changes to the repository.
  • If suppose something goes wrong, make corrections to the last commit and then push that changes to the repository.

77. How do you get a Git Repository?

Ans:

Git repository can be obtained in any of the following two ways:

  1. 1. Users can use a local directory which is not under version control that time. Convert that to a Git Repository.
  2. 2. Users can take an existing Git Repository and can clone it.

Both these options will create a Git Repository in the user’s local machine.

78. How do you view the commit history?

Ans:

After creating various commits or by cloning a repository using an existing commit history, users can check the commit history using git log command. Git hub contains simple examples in a basic project folder called ‘simple git’. You have to run the project using the command:

  • $git  clone https://github.com/schacon/simplegit-progit
  • $git log

The output could looks like this:

$git log

Commit dg56agghbx34987ahj4567845z67a4765az790dc43

Author:………………………………..

Date…………………………………..

Version  number changed

Commit 76545adgg745a564dg7421j45690xcz3679axcvbn6

Author:………………………………..

Date…………………………………..

Removed unwanted test

Commit 124adhkk468900afcjlll129kk480837adcv4689axny8

Author:………………………………..

Date…………………………………..

First commit

The git log command lists the commands present in that repository in the reverse order by default. The most recent commit will be shown first. `In the command list present above, it contains a commit along with the secured hash SHA1 checksum, name of the author, his e-mail id, date authored and the commit message.

79. What is the difference between author and committer in Git?

Ans:

Author is the person who authored the project i.e., who originally wrote the project. Committer is the person who committed changes to the project recently. Therefore, if an user sends a patch to a project and if any of the members in the group applies the patch, both the author and the committer will be credited.

80. How will you undo things in Git?

Ans:

Generally, humans were prone to errors. Git allows some basic tools to undo changes which are made by a user. But, we can’t undo everything. So, a user has to be cautious while doing a work or he may suffer in loss of the work in Git. Commonly, we use this undo option while we commit very early and forget to add some files to it. Sometimes, the commit message might go wrong. In those cases, users can redo that commit. User can change what he actually wanted to do and then he can commit again through –amend option

  • $git commit –amend

This command uses your staging for the commit.

81. What do you mean by remote repository in Git?

Ans:

If the user wishes to combine or merge on any Git project, he must know about managing the remote repositories. Remote repository refers to a version of a project which is hosted over the internet or in a network elsewhere. We may find various remote repositories and every repository among them will perform read/write operations or read-only operations. Merging with some other’s work needs to manage these remote repositories. Users have to push/pull data to and fro from them while sharing our work to others. Managing remote repositories will perform many of the following tasks: user has to know the manner to add remote  repositories, delete some remote repositories which are not valid, have to manage several branches by defining every branch whether they are tracked or not and many more.

82. How will you add remote repositories in Git?

Ans:

Users can use the git clone command which actually adds the origin remote for him. For an instance, if the user wishes to add a new remote repository in Git as a short name, run this command:

  • $git remote add<Short name><URL>
  • $git remote
  • Origin
  • $git remote add pb https://github.com/author1/ticgit
  • $git remote-v

Origin https://github.com/author1/ticgit …………………. Fetching

Origin https://github.com/author1/ticgit…………………… Pushing

Pb https://github.com/author2/ticgit…………………………Fetching

Pb https://github.com/author2/ticgit………………………….Pushing

Instead of using the URL, we can use the string pb on the command line now. For instance, let’s consider the user likes to fetch the entire information from author 2 which is not present in his repository, he can use git fetch pb command.

  • $git fetch pb

Remote: counting objects, 59 completed.

Remote: compressing objects: 100% (48/48., completed

Remote: Total 59 (delta 13., reused 43 (delta 8.

Unpacking objects: 100% (59/59. completed

From https://github.com/author2/ticgit.

*[new branch]  master  …… pb/master

*[new branch]  ticgit  …… …pb/ ticgit

Information present in the repository of author 2 will be accessed locally through pb/master. Users can now combine it with any of the branches.

83. How will you list your tags in Git?

Ans:

Git has a support to add tags to some particular points in the history of a repository which we feel is important. Adding tags is one of the most common features present in Version control systems. Generally, users use this feature to spot release points. Users can list the existing tags uite easily in Git. The command ‘git tag’ will list the tags.

  • $git tag
  • V1.0
  • V2.0

This command will list the tags used in the alphabetical order.

84. What are the types of tags that Git supports? Explain them.

Ans:

There are two types of tags supported by Git. They are:

  1. 1. Lightweight tag
  2. 2. Annotated tag

Lightweight tags never change. It works like a branch. These tags are actually a pointer to a particular commit.

Annotated tags were stored as entire objects in the Git DB. These types of tags were check summed and consisted of the name of the tagger, date, his mail id, the tagging message. Further, the tag has to be signed and verified by the GPG (GNU Privacy Guard..

85. How will you create annotated tags?

Ans:

Users can create an annotated tag in Git quite easily. git tag –a will create an annotated tag. The command to create such a tag is:

  • $ git tag –a v1.5 –m “using version 1.5”
  • $ git tag
  • V0.1
  • V1.3
  • V1.4

Here, -m will contain a tagging message specified by the tagger, which can be saved with the tag. If you want to see the tag data present and also the commit which is tagged using git, you can use the git show command. This command shows the information of the tagger, the date of the commit tagged and also the tagger message and the commit information.

86. Write the workflow of branching and merging with some examples?

Ans:

Branching and Merging in practice requires some stage of operations to be performed. Let’s explain the process with a simple example

  1. 1. Make some work on a website
  2. 2. Build a branch for a new user
  3. 3. Now, start doing some work in the created branch
  4. 4. If suppose, some bug occurs at this stage and it is need to be fixed asap, perform the following operations:
  5. 5. Move to the user’s production branch
  6. 6. Build a branch to clear the bug
  7. 7. Once you test it, combine the hotfix branch and then push it to production
  8. 8. Move to your actual work from where you switched and start working on it.

87. What do you mean by long running branches?

Ans:

Because of its enhanced feature support to the users, Git offers three way easy merging of one branch to another several times for a long period. Many branches were always open which can be used in various stages of your development cycle which can be merged often from few of them to others. The code in the master branch will be completely stable which is the only possible code which has been released. Developers who use Git generally use this kind of technique. Developers use yet another parallel branch called ‘next’ or ‘develop’ to work or to test the stability but there is no certainty to be stable always. Once it reaches the stable state, it can further be merged to the master. Normally, they are used to pull from topic branches once they are stable which ensures they could clear all the tests without any errors.

88. What do you mean by topic branches?

Ans:

As opposed to long running branches, topic branches are short lived branches. If an user needs to create a project of any size, he can go for topic branches. These types of branches can be built and used for one specific feature or task. This particular feature will not be available in any of the version control systems because this feature is not cost effective to build and combine branches. But, Git supports this feature. Using Git, this can be very ordinary for building, merging, working and deleting branches many times in a day.

89. How will you track remote branches in Git?

Ans:

Tracking remote branches in Git can be done by checking a local branch. This monitoring will create a branch automatically which is called a tracking branch. A tracking branch track is so called as an upstream branch. These tracking branches will establish a direct connection with a remote branch. They are local branches. Tracking a remote branch can be done using ‘git pull’. Once you type this command, Git automatically understands which server to be fetched and which branch has to be merged.

90. Explain the protocols that Git uses to transfer data.

Ans:

To transfer data, Git mainly uses the following four protocols:

  1. 1. Local
  2. 2. HTTP
  3. 3. SSH
  4. 4. Git

Local protocol is the generally used protocol by developers and is the very basic protocol.  In a local protocol, the remote repository is present in another directory with the same host. This protocol will be used if every member in a team enjoys access to a shared file system like NFS mount or sometimes every person in the team creates logs from the same computer. The second option might create catastrophic loss generally since all of your code repositories will be present in the same computer and therefore using this option is not advised.

Git also uses HTTP protocol for communication using two different modes:

  1. 1. Smart HTTP
  2. 2. Dumb HTTP

Smart HTTP protocol functions much similar to SSH or Git protocols but could run in standard HTTP ports using several authentication mechanisms of HTTP. If suppose the server haven’t responded with smart HTTP mechanism, the Git client will switch to the simpler Dumb HTTP protocol. Dumb protocol can be set up uite simply. User has to place a bare Git repository in the HTTP root document and has to set up a particular post-update hook. After this, anyone who wishes to access the web server where you put the repository and also they can clone the repository.

SSH protocol is another common protocol for data transport for Git to self host through SSH. SSH protocol is set up more commonly in most places and it is very simple to do if we didn’t. It is also an authenticated network protocol

Git protocol contains a special daemon which contains as a package with Git. This protocol works on a dedicated port and doesn’t contain any authentication. This protocol works similar to SSH.

91. How can you resolve merge conflicts through the command line?

Ans:

Generally merge conflicts happen while the user alters one line of a file or if one deletes the same file and another edits the same file. To resolve such conflict, the user has to choose the change we need to make from several branches in a new commit. Before merging branches, users have to resolve this kind of merge conflict with a new commit.

Open the terminal window : TerminalGit Bash the terminal

Move to the local Git repository which contains the merge conflict

  • cd REPOSITORY –NAME

92. Create a list of files which contains merge conflict?

Ans:

Open the text editor of your wish (namely Atom. and move to the file which contains merge conflicts.

To identify the starting point of the merge conflict from your file, search that file for the conflict marker.

If the user likes to retain his branch’s changes alone, retain that changes else make some changes which will make changes in both of the branches. Then, delete the conflict markers and do changes in the final merge you wish to make.

Now, add a change or stage your changes

  • $ git add

Then, commit your changes using some comment.

  • $ git commit –m “Merge Conflict is resolved”

93. What do you mean by a bare repository?

Ans:

Generally a bare repository in Git will contain details about the version control and the idle files (files not working. and also it won’t have the special Git subdirectory. But, the repository will contain the Git subdirectory contents in its main directory and the current working directory will contain it. a Git subdirectory consisting of Git connected history of user’s repository and ii. verified copies of user’s project file(working tree..

94. Explain the steps to resolve a conflict in git?

Ans:

The following are the steps to resolve a conflict in Git:

  1. 1. Locate the files which generated the conflict.
  2. 2. Do required changes to the files and ensure the conflict won’t repeat again.

95. How will you differentiate between Git and GitHub?

Ans:

Git is a high-quality version control system. It is distributed in nature and is employed to track changes in source code throughout software development. It has a unique branching model that helps in synchronizing work among developers and tracking changes in any files.

The primary goals of Git are speed, data integrity, providing support to distributed, non-linear workflows. Git is installed and maintained on the local machine, instead of the cloud.

GitHub is a cloud-based Git repository hosting service that brings teams together. It gives you a web-based GUI as well as provides access control and many collaboration features, fundamental task management tools for each project.

Also, GitHub is an open-source i.e. code is kept on a centralized server and can be accessed by everyone.

96. What are the advantages of Git over SVN?

Ans:

Since Git is an open source version control system it lets you run multiple versions of your project so that it shows the changes that are made to the code over time and if needed you can keep a track of the changes that you have made. This means that large number of developers can make their own changes and upload those changes so that the changes can be attributed to the particular developers

97. Why do we need branching in GIT?

Ans:

With the help of branching you can have your own branch and you can also jump between the various branches. You can go to your previous work while at the same time keeping your recent work intact.

98. What is the regular way for branching in GIT?

Ans:

The best way to create a branch in GIT is to have one ‘main’ branch and then create another branch for implementing the changes that you want to make. This is extremely useful when there are a large number of developers working on a single project.

99. How to identify if a certain branch has been merged into master?

Ans:

Git branch –merged master – shows all branches that are merged into master

Git branch – merged – shows all branches that are merged into the head

Git branch – no-merged –shows all the branches that are not merged

Are you looking training with Right Jobs?

Contact Us

Popular Courses