Top 50 Interview Questions on VCS Git & GitHub
1. What is GIT?
GIT may be a distributed version system and ASCII text file management (SCM) system with a stress to handle small and enormous projects with speed and efficiency.
2. What are the advantages of using GIT?
Here are some of the most important advantages of Git:
- Data redundancy and data replication is possible
- It is a highly available service
- For one repository you’ll have just one directory of Git
- The network performance and disk utilization are excellent
- It is very easy to collaborate on any project
- You can work on any kind of project within the Git
3. What language is used in GIT?
C is the programming language that’s used for creating Git which ensures that the overheads are reduced.
4. What are the benefits of Git over SVN?
Since Git is an open source version system it allows you to run multiple versions of your project in order 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 a large number of developers can make their own changes and upload those changes so that the changes can be attributed to the particular developers.
5. what’s the meaning of “Index” or “Staging Area” in GIT?
When you are making the commits you can make changes to it, format it and review it in the intermediate area known as ‘Staging Area’ or ‘Index’.
6. What is GIT stash?
The Git stash will take the working directory within the current state and index it to place on the stack at a later stage in order that what you get is a clean working directory. This means that if you’re within the middle of some task and wish to urge a clean working directory and simultaneously you would like to stay all of your current edits and then you can use the Git stash.
7. What is GIT stash drop?
When you finished working on the stashed item or want to remove the list then you can use the Git stash drop. This will ensure that the item that is last added by default or any particular item can be removed from the argument.
8. the way to identify if a particular branch has been merged into master?
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
9. What’s the utilization of a Git clone?
The Git clone command allows you to copy the prevailing Git repository. If you want to get a copy of the central repository then the best way to do it is using ‘cloning’.
10. What is the function of ‘git config’?
The ‘Git config’ is a great way to configure your options for the Git installation. Using this command you’ll define the repository behavior, preferences and user information.
11. What constituents are used for the commit object?
- The state of a project at a given point of time is contained in a set of files
- Parent object commit references
- A 40-character string that uniquely identifies the commit object called by a name SHAI
12. What’s the method for creating a repository in Git?
If you would like to make a repository in Git then you would like to run the command “git init”. With this command .git repository you’ll create a directory within the project directory.
13. What is ‘head’ in git and how many heads can be created in a repository?
The reference to a commit object is called the ‘head’. Every repository has a ‘Master’ which is the default head. There can be multiple heads in a repository.
14. Why do we need branching in GIT?
With the assistance of branching you’ll have your own branch and you’ll also jump between the varied branches. You can attend your previous work while at an equivalent time keeping your recent work intact.
15. What is git cherry-pick?
- Cherry picking in git means to settle on a commit from one branch and apply it onto another.
- This is in contrast with other ways like merge and rebase which normally applies many commits onto another branch.
- Make sure you’re on the branch you would like to use the plan to . git checkout master Execute the following:
git cherry-pick
16. How to revert previous commit in git?
To revert to a previous commit and to ignoring any changes:
git reset — hard HEAD
where HEAD is that the last commit in your current branch
17. what’s the command you’ll use to write down a commit message?
The command that I want to write a commit message is “git commit –a”. The –a on the instruction instructs git to commit the new content of all tracked files that are modified. You can use “git add” before git commit –a if new files got to be committed for the primary time.
18. What is the difference between GIT and SVN?
The difference between GIT and SVN is
a) Git is a smaller amount preferred for handling extremely large files or frequently changing binary files while SVN can handle multiple projects stored within the same repository.
b) GIT doesn’t support ‘commits’ across multiple branches or tags. Subversion allows the creation of folders at any location within the repository layout.
c) Gits are unchangeable, while Subversion allows committers to treat a tag as a branch and to make multiple revisions under a tag root.
19. How can you create a repository in Git?
In Git, to make a repository, create a directory for the project if it doesn’t exist, then run command “git init”. By running this command .git directory is going to be created within the project directory, the directory doesn’t have to be empty.
20. How can you bring a new feature to the main branch?
To bring a replacement feature within the main branch, you’ll use a command “git merge” or “git pull command”.
21. What is a ‘conflict’ in git?
A ‘conflict’ arises when the commit that has got to be merged has some change in one place, and therefore the current commit also features a change at an equivalent place. Git won’t be ready to predict which change should take precedence.
22. How can conflict in git be resolved?
To resolve the conflict in git, edit the files to repair the conflicting changes then add the resolved files by running “git add” then to commit the repaired merge, run “git commit”. Git remembers that you simply are within the middle of a merger, so it sets the oldsters of the commit correctly.
23. To delete a branch what’s the command that’s used?
Once your development branch is merged into the most branch, you don’t need
development branch. The command “git branch –d [head]” is used to delete a branch .
24. What’s an alternative choice for merging in git?
“Rebasing” is an alternative to merging in git.
25. What’s the syntax for “Rebasing” in Git?
The syntax “git rebase [new-commit]” is used for rebase.
26. What is the common branching pattern in GIT?
The common way of making branch in GIT is to take care of one as “Main“
branch and make another branch to implement new features. This pattern is especially useful when there are multiple developers performing on one project.
27. what’s the difference between ‘git remote’ and ‘git clone’?
‘git remote add’ just creates an entry in your git config that specifies a reputation for a specific URL. While, ‘git clone’ creates a replacement git repository by copying an existing one located at the URI.
28. What is GIT version control?
With the assistance of GIT version control, you’ll track the history of a set of files and include the functionality to revert the gathering of files to a different version. Each version captures a snapshot of the file system at a certain point of time. A collection of files and their complete history are stored during a repository.
29. What is Subgit? Why to use Subgit?
‘Subgit’ may be a tool for a smooth, stress-free SVN to Git migration. Subgit may be a solution for a corporation -wide migration from SVN to Git that is:
a) It is much better than git-svn
b) No requirement to vary the infrastructure that’s already placed
c) Allows to use all git and every one sub-version features
d) Provides genuine stress –free migration experience.
30. What is ‘bare repository’ in GIT?
To coordinate with the distributed development and developers team, especially once you are performing on a project from multiple computers ‘Bare Repository’ is employed . It comprises a version history of your code.
31. Mention the various Git repository hosting functions?
- Github
- Gitlab
- Bitbucket
- SourceForge
- GitEnterprise
32. How can you fix a broken commit?
In order to fix any broken commit, use the command “git commit –amend”. When you run this command, you can fix the broken commit message in the editor.
33. How is git instaweb used?
‘git instaweb’ is used to automatically direct an online browser and run a webserver with an interface into your local repository.
34. What is git is-tree?
‘git is-tree’ represents a tree object including the mode and therefore therefore the name of every item and the SHA-1 value of the blob or the tree.
35. What is the difference between git pull and git fetch?
Git pull command pulls new changes or commits from a specific branch from your central repository and updates your target branch in your local repository.
Git fetch is additionally used for an equivalent purpose but it works during a slightly different way. When you perform a git fetch, it pulls all new commits from the specified branch and stores it during a new branch in your local repository. If you would like to reflect these changes in your target branch, git fetch must be followed with a git merge. After merging the target branch and fetched branch your target branch will only be updated. Just to make it easy for you, remember the equation below:
Git pull = git fetch + git merge
36. What is the difference between the ‘git diff ’and ‘git status’?
‘git diff ’ depicts the changes between commits, commit and dealing tree, etc. whereas ‘git status’ shows you the difference between the working directory and therefore the index, it’s helpful in understanding a git more comprehensively. ‘git diff’ is analogous to ‘git status’, the sole difference is that it shows the differences between various commits and also between the working directory and index.
37. What does ‘hooks’ comprise of in Git?
This directory consists of shell scripts, if you run the corresponding Git commands that shell scripts are activated. For example, git will attempt to execute the post-commit script after you’ve run a commit.
38. Are you able to explain the Gitflow workflow?
To record the history of the project, Gitflow workflow employs two parallel long-running branches – master and develop:
Master – this branch is usually able to be released on LIVE, with everything fully tested and approved (production-ready).
Hotfix – these branches are wont to quickly patch production releases. These branches are tons like release branches and have branches except they’re supported by the master rather than develop.
Develop – this is often the branch to which all feature branches are merged and where all tests are performed. only everything’s been thoroughly checked and glued can it’s merged to the master.
Feature – each new feature should reside in its own branch, which may be pushed to the develop branch as their parent one.
39. What is the difference between HEAD, working tree and index, in Git.
The working tree/working directory/workspace is that the directory tree of (source) files that you simply are ready to see and edit.
The index/staging area may be a single, large, computer file in <baseOfRepo>/.git/index, which lists all files within the current branch, their SHA-1 checksums, timestamps, and therefore the file name – it’s not another directory which contains a replica of files in it.
HEAD is employed to ask the last commit within the currently checked-out branch.
40. What’s the difference between rebase and merge in Git?
In Git, the rebase command is employed to integrate changes from one branch into another. it’s an alternate to the “merge” command. The difference between rebase and merge is that rebase rewrites the commit history so as to supply a straight, linear succession of commits.
Merging is a way of putting a forked history back together again. The git merge command helps you take the independent lines of development created by git branch and integrate them into one branch.
41. Explain the difference between reverting and resetting?
Git reset may be a powerful command that’s wont to undo local changes to the state of a Git repository. Git reset operates on “The Three Trees of Git” which are, Commit History ( HEAD ), the Staging Index, and therefore the Working Directory.
Revert command in Git creates a replacement commit that undoes the changes from the previous commit. This command adds a replacement history to the project. It doesn’t modify the prevailing history.
42. What’s Git Fork? What’s the difference between fork, branch, and clone?
A fork may be a copy of a repository. Normally you fork a repository in order that you’re ready to freely experiment with changes without affecting the first project. Most ordinarily , forks are wont to either propose changes to someone else’s project or to use someone else’s project as a start line for your own idea.
git cloning means pointing to an existing repository and making a replica of that repository during a new directory, at another location. The first repositories are often located on the local filing system or on remote machine accessible supported protocols. The git clone command is employed to make a replica of an existing Git repository.
Within a git repository Git branches are individual projects . Different branches within a repository can have completely different files and folders, or it could have everything equivalent apart from some lines of code during a file.
43. How does one find an inventory of files that have changed during a particular commit?
git diff-tree -r {hash}
Given the commit hash, this may list all the files that were changed or added therein commit. The -r flag makes the command list individual files, instead of collapsing them into root directory names only.
The output also will include some extra information, which may be easily suppressed by including a few of flags:
git diff-tree –no-commit-id –name-only -r {hash}
Here –no-commit-id will suppress the commit hashes from appearing within the output, and –name-only will only print the file names, rather than their paths.
44. What is a clone in GitHub?
Cloning a Git repository means we will create an area copy of the code provided by the developer. You can simply roll in the hay with a command line: git clone git://github.com/facebook/facebook-ios-sdk.git . and we can have the code within the facebook-ios-sdk directory.
45. How much space do we get on GitHub?
We get a space of 1 GB but if it exceeds 1GB, we receive a polite email from GitHub Support requesting to reduce the size of the repository and scale it down. In addition, here we placed a limit of files exceeding 100 MB in size.
46. Can you explain about Branching and Merging in GIT?
The Git feature that basically makes it stand aside from nearly every other SCM out there’s its branching model.
Git allows and encourages you to possess multiple local branches which will be entirely independent of every other. The creation, merging, and deletion of these lines of development takes seconds.
47. What does git pull origin master do?
It pulls the master branch from the remote called origin into your current branch. It does not affect your local master It only affects your current branch.
48. What is git pull origin?
pull is a fetch and a merge. * `git pull origin master` fetches commits from the master branch of the origin remote (into the local origin/master branch), and then it merges origin/master into the branch you currently have checked out.
49. Explain the difference between pull request and branch?
- A branch is simply a separate version of the code.
- A pull request is when someone takes the repository, does some changes, makes their own branch, then tries to merge that branch in .
50. What are the common Git commands and their uses?
Here are some of the common Git commands, along with their functions.
- GIT diff – It shows the changes between commits, commits and dealing tree.
- GIT status – It shows the difference between index and working directories.
- GIT stash applies – it’s wont to bring back the saved changes on the working directory.
- GIT rm – It removes the files from the area and also of the disk.
- GIT log – it’s wont to find the precise commit within the history.
- GIT add – It adds file changes within the existing directory to the index.
- GIT reset – it’s wont to reset the index and also because the working directory to the state of the last commit.
- GIT checkout – it’s wont to update the directories of the working tree with those from another branch without merging.
- GIT Is tree – It represents a tree object including the mode and therefore the name of every item.
- GIT instaweb – It automatically directs an internet browser and runs the online server with an interface into your local repository.