In this article, we have brought you 75 interview questions on Git covering types like Multiple Choice Questions(MCQs) and Descriptive questions.
Table of Contents:
- Descriptive questions
- Fill in the blanks
Multiple Choice Questions(MCQs)
1. What comes first?
(A) $ git add
(B) $ git commit
Explanation: 'git add' command adds a change in the working directory and then the changes are committed.
2. Which among the following is a distributed version control system?
Explanation: Perforce and Svn are centralized version control systems whereas docker is a container.
3. After you add a file, it becomes
Explanation: The staging steps allows you to keep making changes in the working directory.
4. What is equivalent to fetch and merge?
Explanation: Both of them refer to retrieving latest meta-data info from the original.
5. What command lets you create connection between a local and remort repository?
(A) git remote add origin
(B) git remote add new
(C) git remote new origin
(D) git remote orgin
Explanation: This is useful for developers creating a local copy of a central repository, since it provides an easy way to pull upstream changes or publish local commits.
6. Arranging given data in descending order is an example of?
(A) Information processing
Explanation: Data arrangement allows easier processing of data and provides extra security to the data as well.
7. How do you supply a commit message to a commit?
(A) Git message "My first commit"
(B) Git add "My first commit"
(C) Git commit "My first commit"
(D) Git commit -m "I'm coding!"
Explanation: Just make use of the give format and add your message.
8. Git shortcut to stage all the changes made?
(A) Git commit add .
(B) Git commit .
(C) Git add .
(D) Git stage -a .
Explanation: add command stages all the changes made.
9. Which two configuration properties does the tool expect to be configured after installing Git and prior to issuing the first commit?
(A) email address and password
(B) username and email address
(C) username and IP address
(D) username and password
Explanation: User authenticaion and authorization is done via username and password.
10. What do you call a system the records the project code's changes over time?
(A) Repository System
(B) Code Change System
(C) Version Control System
(D) none of the above
Explanation: Version control system helps software teams manage changes to source code over time.
11. Who invented Git?
(A) unio C. Hamano
(B) Linus Torvalds
(C) James Gosling
(D) Kohsuke Kawaguchi
Explanation: Linus Torvalds invented Git in 2005 for development of the Linux kernel.
12. Git commit -m < ? >, ? is for?
(A) file name to be commited
(C) repo url
Explanation: ? is replaced by the comments that the user wants to add.
13. Command to check out a branch from the repository in the working directory?
(A) git init
(B) git checkout
(C) git add
(D) git commit
Explanation: The git checkout command lets you navigate between the branches created by git branch.
14. Command to create a new git branch?
(A) git checkout branchname
(B) git create-branch branchName
(C) git branch branchName
(D) git -b branchName
Explanation: replace branchName with the desired name that you want to give to the concerned branch.
15. Git command if I want to commit my changes about "Initial commit"
(A) git commit -m "Initial commit"
(B) git commit -msg "Initial commit"
Explanation: The "commit" command is used to save your changes to the local repository.
16. Command to make new git branch
(A) git branch
(B) git -b
(C) git new branch
(D) git checkout branch
17. How do you check the state of your local git repository since your last commit?
(A) git check
(B) git diff
(C) git commit
(D) git status
Explanation: status command gives you the changes made in the local git repository since the last commit.
18. Command to add particular file changes to staging area from working directory?
(A) git pull
(B) git add .
(C) git add filename
(D) git commit -m
Explanation: Just replace the filename with the file to which the changes needs to be added.
19. Which of the following is one of Git's powerful features?
Explanation: Git branches are effectively a pointer to a snapshot of your changes.
20. Which of the following will create new branch?
(A) git checkout new-branch
(B) git checkout -b new-branch
(C) git clone new-branch
(D) git create-branch new-branch
*Explanation: The git branch command can be used to create a new branch.
21. What are the different options for git reset?
(D) All of above
Explanation: git reset is a powerful command that is used to undo local changes to the state of a Git repo.
22. How would you commit this with the message "adding new authors to index"?
(A) git commit -m "adding new authors to index"
(B) git commit "adding new authors to index"
(C) git commit .
(D) none of the above
Explanation: For adding new authors one needs to create indexes in the already existing tree.
23. Which of the following is the correct way to initialize a new Git repository?
(A) git add .
(B) git init
(C) git commit
(D) none of the above
Explanation: The git init command creates a new Git repository.
24. Which one of them is incorrect command?
(A) git add Test.txt
(B) git pull origin master
(C) git push origin master
Explanation: All the commands given are correct.
25. Command to connect to local repo with remote repo?
(A) git init
(B) git remote add
(C) git connect repo
(D) git configure
Explanation: This is helpful in refelecting the changes made in the local repository.
26. Which programming language was used initially to create git?
Explanation: Because it provided wrappers around the programs written.
27. What command removes untracked files from your working directory?
(A) git commit
(B) git clean -f path
(C) git clean
(D) git reset
Explanation: The git clean command can be used to untracked individual files or a collection of files.
28. What is the default text editor for the Bash shell with a Windows-based Git install?
Explanation: Because Vim text editor has built-in terminal.
29. Which file can you configure to ensure that certain files are never committed to the local Git repository?
Explanation: It tells Git which files and directories to ignore when you make a commit.
30. Which command should you use to initialize a new git repository?
(A) Git install
(B) Git start
(C) Git bash
(D) Git init
Explanation: The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.
31. Which of the following commands will merge branch-a into the master branch?
(A) git merge master and git checkout branch-a
(B) git checkout branch-a and git merge master
(C) git checkout master and git merge branch-a
(D) git merge branch-a and git checkout master
Explanation: First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch.
32. Which vendor acquired GitHub for $7.5 billion in June 2018?
Explanation: Microsoft acquired Github for $7.5 billion in June 2018.
33. Which of the following is not a Git configuration scope?
Explanation: Local, System and Global are some of the Git configuration scope.
34. Command to check the created, modified, deleted files in gitbash before Commit?
(A) git show
(B) git log
(C) git status
(D) all of the above
Explanation: The git status command displays the state of the working directory and the staging area.
35. Which command is useful for getting a high-level overview of the project history?
(A) git log --oneline
(B) git reset --hard
(C) git log --author="pattern"
(D) git rebase base
Explanation: The oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message.
36. What will the following command print to the Terminal?git remote -v
(A) The current git version you're running
(B) An inline editor for modifying remote repositories
(C) A list of remote repositories you are connected to
(D) The last 5 git versions you've installed
Explanation: Lists the current remotes associated with the local repository.
37. Git reset --hard used to?
(A) uncommitted the changes, unstage the changes
(B) uncommitted the changes
(C) uncommitted the changes, unstage the changes, delete the changes
(D) Unstage the changes
Explanation: git reset --hard option resets the current branch tip, and also deletes any changes in the working directory and staging area.
38. Command to show limited number of commits?
(A) git fetch remote
(B) git log -n limit
(C) git config limit
(D) git status
Explanation: git log -n where n represents the number up to which commit you to want to see the logs.
39. Which of the following commands will allow you to change branches?
(A) git checkout
(B) git clone
(C) git add
(D) git commit
Explanation: In Git terms, a "checkout" is the act of switching between different versions of a target entity. The git checkout command operates upon three distinct entities: files, commits, and branches.
40. Command to switch between branches?
(A) Git branch
(B) Git checkout
(C) Git switch
(D) Git merge
Explanation: Use git checkout new_branch to switch to that branch.
1. What is Git?
Git is a Distributed Version Control system(DVCS). It lets you track changes made to a file and allows you to revert back to any particular change that you wish. It is a distributed architecture that provides many advantages over other Version Control Systems (VCS) like SVN. One of the major advantages is that it does not rely on a central server to store all the versions of a project’s files.
2. What is a distributed VCS?
In Distributed VCS, every contributor can get a local copy or “clone” of the main repository. With an operation called “pull”, they can update their local repositories with new data from the central server and “pull” operation affects changes to the main repository from their local repository.
3. What is Git bisect? How can you use it to determine the source of a (regression) bug?
Git bisect is used to find the commit that introduced a bug by using binary search. The command for Git bisect is
git bisect subcommand options
This command uses a binary search algorithm to find which commit in your project’s history introduced a bug. You use it by first telling it a “bad” commit that is known to contain the bug, and a “good” commit that is known to be before the bug was introduced. Then Git bisect picks a commit between those two endpoints and asks you whether the selected commit is “good” or “bad”. It continues narrowing down the range until it finds the exact commit that introduced the change.
4. What is git cherry-pick?
The command git cherry-pick is normally used to introduce particular commits from one branch within a repository onto a different branch. Another common use is to forward- or back-port commits from a maintenance branch to a development branch. This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch.
git cherry-pick commit-hash
5. Explain the difference between reverting and resetting.
Git reset operates on “The Three Trees of Git” which are, Commit History ( HEAD ), the Staging Index, and the Working Directory. Revert command in Git creates a new commit that undoes the changes from the previous commit. This command adds a new history to the project. It does not modify the existing history.
6. What is the difference between rebasing and merge in Git?
In Git, the rebase command is used to integrate changes from one branch into another. Merging is Git’s way of putting a forked history back together again.
7. What is git is-tree?
‘git is-tree’ represents a tree object including the mode and the name of each item and the SHA-1 value of the blob or the tree.
8. How is git instaweb used?
It is used to automatically direct a web browser and run a webserver with an interface into your local repository.
9. What is repository in a git?
Repository in Git is a place where Git stores all the files. Git can store the files either on the local repository or on the remote repository.
10. What language used in git?
Git uses ‘C’ language. GIT is fast, and ‘C’ language makes this possible by reducing the overhead of run times associated with high-level languages.
11. Mention some Git repository hosting functions?
Github, Gitlab, Bitbucket, SourceForge and GitEnterprise
12. What is a commit message?
A shortcut command that immediately creates a commit with a passed commit message.
13. How can you create a repository in git?
To create a repository, create a directory for the project if it does not exist, then run the command “git init”. By running this command .git directory will be created in the project directory.
14. What is 'bare repository' in git?
A “bare” repository in Git contains information about the version control and no working files (no tree) and it doesn’t contain the special .git sub-directory.
15. What is 'conflict' in git?
A conflict arises when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other. Conflicts will most likely happen when working in a team environment.
16. Write the steps to resolve a conflict in git?
- Identify the files that have caused the conflict.
- Make the necessary changes in the files so that conflict does not arise again.
- Add these files by the command git add.
- Finally to commit the changed file using the command git commit
17. What is subgit?
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.
18. What is the difference between git pull and git fetch?
Git pull is used to pull the the new changes or commits from a particular branch from your central repository and updates the target branch in the local repository.
Git fetch is also used for the same purpose, but for reflecting all the changes in the target branch, git fetch must be followed with git merge.
19. What is 'staging area' or 'index' in git?
Git Index may be defined as the staging area between the workspace and the repository. The major use of Git Index is to set up and combine all changes together before you commit them to your local repository.
20. What is the function of 'git statsh apply'?
It allows users to resume the work from where they left, hence the command is used to bring back the saved changes onto your current working repository.
21. What is the difference between 'git remote' and 'git clone'?
‘git remote add’ creates an entry in your git config that specifies a name for a particular URL whereas ‘git clone’ creates a new git repository by copying an existing one located at the URL
22. What is the function in 'git config'?
Git uses your username to associate commits with an identity. The git config command can be used to change your Git configuration, including your username.
23. What is the function of 'git stash drop'?
Git ‘stash drop’ command is used to remove the stashed item. It will remove the last added stash item by default, and it can also remove a specific item if you include it as an argument.
24. What does 'hooks' comprise of in git?
This directory consists of shell scripts that are activated if you run the corresponding Git commands. For example, git will try to execute the post-commit script after you have run a commit.
25. What does the git reset --mixed and git merge --abort commands do?
git reset --mixed is used to undo changes made in the working directory and staging area.
git merge --abort helps stop the merge process and return back to the state before the merging began.
Fill in the blanks
1. Git ______ means pointing to an existing repository and make a _____ of repository in a new directory in the same _____
Ans: cloning, copy and same
2. Git _______ are individual projects within a git repository.
3. The ______ branching strategy keeps all of the changes for a particular feature inside of a branch.
4. _______ defines a strict branching model designed around the project release.
Ans: Gitflow Workflow
5. A commit object contains ______, ________ and _________
Ans: set of files, reference to parent and SHA1 name
6. _______ consists of all the metadata of the repository.
Ans: .git directory
7. In _________ each task is implemented on its own branch with the task key included in the branch name.
Ans: Task Branching
8. Developers can push to their own _________ repositories while only the project maintainer can push to the _________.
Ans: server-side, official repository
9. ________ configures the username and email address.
Ans: Git config
10. The _________ command only downloads new data from a remote repository.
Ans: Git fetch