Search Tutorials


Git MCQ Questions and Answers | JavaInUse

Git MCQ Questions and Answers

Q. What is Git?

A. A version control system
B. A project management tool
C. A collaboration platform
D. A software development framework

Q. What is the purpose of branching in Git?

A. To create a new repository
B. To merge two repositories
C. To create a new version of a project
D. To work on different features or changes in isolation

Q. What is a commit in Git?

A. A change to a file
B. A new branch
C. A snapshot of the repository at a specific point in time
D. A request to make changes to a file

Q. How do you create a new branch in Git?

A. git init
B. git branch <branch_name>
C. git checkout -b <branch_name>
D. git switch -c <branch_name>

Q. How do you switch between branches in Git?

A. git switch <branch_name>
B. git checkout <branch_name>
C. git branch <branch_name>
D. git change <branch_name>

Q. What is a remote repository in Git?

A. A local copy of a repository
B. A repository hosted on a remote server
C. A repository with read-only access
D. A repository with write-only access

Q. How do you add a remote repository in Git?

A. git add remote <remote_name> <remote_url>
B. git remote add <remote_name> <remote_url>
C. git add <remote_name> <remote_url>
D. git remote <remote_name> <remote_url>

Q. How do you push changes to a remote repository in Git?

A. git push origin master
B. git push remote master
C. git push origin <branch_name>
D. git push remote <branch_name>

Q. How do you pull changes from a remote repository in Git?

A. git pull origin master
B. git fetch origin master
C. git pull remote master
D. git fetch remote master





Q. What is a merge conflict in Git?

A. When two branches have conflicting changes
B. When a commit cannot be pushed to a remote repository
C. When a file is deleted in one branch but modified in another
D. When two developers try to push changes to the same file at the same time

Q. How do you resolve a merge conflict in Git?

A. Use the git merge --resolve command
B. Edit the conflicting file and choose the changes to keep
C. Revert one of the conflicting commits
D. Create a new branch and merge the changes again

Q. What is Git rebase?

A. A command to undo changes
B. A way to move a branch to a new base commit
C. A command to reset the repository to a previous state
D. A tool for merging branches

Q. What is Git stash?

A. A way to temporarily store changes
B. A command to undo the last commit
C. A tool for merging branches
D. A way to create a new branch

Q. How do you tag a specific commit in Git?

A. git tag <tag_name>
B. git label <tag_name>
C. git mark <tag_name>
D. git point <tag_name>

Q. How do you delete a remote branch in Git?

A. git remote rm <remote_name>
B. git branch -d <remote_name>
C. git push origin --delete <branch_name>
D. git remote remove <branch_name>

Q. Which of the following commands is used to create a new Git repository in an existing project directory?

A.
git init
B.
git create
C.
git start
D.
git new

Q. What will be the output of the following Git command sequence?

git add file.txt
git commit -m "Added new file"
A.
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   file.txt
B.
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   file.txt
C.
On branch master
nothing to commit, working tree clean
D.
On branch master
Changes to be committed:
  (use "git reset HEAD^" to uncommit)

	modified:   file.txt

Q. Which of the following Git commands is used to retrieve changes from a remote repository?

A.
git fetch
B.
git pull
C.
git get
D.
git remote get

Q. What will be the output of the following Git command sequence?

git branch
git checkout -b new_branch
A.
master
* new_branch
B.
* master
  new_branch
C.
master
new_branch
* (no branch)
D.
Error: Cannot create new branch

Q. Which of the following Git commands is used to undo changes made to a tracked file in the working directory?

A.
git undo
B.
git reset
C.
git revert
D.
git checkout -- 

Q. What will be the output of the following Git command sequence?

git log --oneline
git reset --hard HEAD~2
A.
34a690d (HEAD -> master) Third commit
0a96a32 Second commit
7e34c84 First commit
B.
0a96a32 (HEAD -> master) Second commit
7e34c84 First commit
C.
34a690d (HEAD -> master) Third commit
0a96a32 Second commit
D.
Error: Invalid number of commits

Q. Which of the following Git commands is used to create a new branch based on a remote branch?

A.
git branch -b <branch_name> origin/<remote_branch_name>
B.
git checkout -b <branch_name> origin/<remote_branch_name>
C.
git branch --remote <branch_name> <remote_branch_name>
D.
git checkout --remote <branch_name> origin/<remote_branch_name>

Q. What will be the output of the following Git command sequence?

git merge new_branch
git branch -d new_branch
A.
Updating f42c576..3a08692
Fast-forward
 file.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt
Deleted branch new_branch (was f42c576)
B.
Updating f42c576..3a08692
Fast-forward
 file.txt | 1 -
 1 file changed, 1 deletion(-)
 create mode 100644 file.txt
Deleted branch new_branch (was f42c576)
C.
Updating f42c576..3a08692
Merge made by the recursive strategy.
 file.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt
D.
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.

Q. Which of the following Git commands is used to push changes to a remote repository?

A.
git push
B.
git send
C.
git remote push
D.
git commit -m "Push changes"

Q. What will be the output of the following Git command sequence?

git tag v1.0
git tag
A.
v1.0
B.
v1.0
v2.0
C.
v1.0
v1.1
D.
Error: Tag already exists