Top 100 Git and GitHub MCQ Questions and Answers

Git and GitHub are essential tools in modern software development for version control, collaboration, and project management. These 100 MCQs are designed to help you better understand Git commands, workflows, and the integration with GitHub.

1. What is Git?

a) A distributed version control system
b) A centralized version control system
c) A text editor
d) A compiler

2. What is the primary purpose of GitHub?

a) To host Git repositories
b) To write code
c) To debug programs
d) To compile code

3. What is the command to initialize a new Git repository?

a) git init
b) git start
c) git create
d) git begin

4. What is a commit in Git?

a) A snapshot of changes
b) A branch
c) A remote repository
d) A bug fix

5. How do you check the status of your Git repository?

a) git check
b) git status
c) git info
d) git log

6. How do you add changes to the staging area in Git?

a) git add
b) git commit
c) git stage
d) git push

7. How do you commit changes in Git?

a) git add
b) git commit
c) git push
d) git save

8. What is the command to view the commit history in Git?

a) git history
b) git log
c) git commit
d) git show

9. How do you remove a file from the staging area in Git?

a) git reset
b) git delete
c) git remove
d) git rm --cached

10. What is a branch in Git?

a) A pointer to a specific commit
b) A remote repository
c) A bug fix
d) A tag

11. What is the command to create a new branch in Git?

a) git branch new-branch
b) git new-branch
c) git checkout branch
d) git switch branch

12. What is the command to switch to another branch in Git?

a) git checkout branch-name
b) git switch branch-name
c) Both a and b
d) git change branch-name

13. How do you merge a branch into the current branch in Git?

a) git merge branch-name
b) git merge commit
c) git combine branch-name
d) git rebase branch-name

14. What is a conflict in Git?

a) When two branches have changes to the same lines of code
b) When a file is deleted
c) When a file is added
d) When the repository is corrupted

15. What is a pull request in GitHub?

a) A request to merge changes from one branch to another
b) A request to delete a branch
c) A request to clone a repository
d) A request to reset a branch

16. How do you clone a Git repository?

a) git clone
b) git pull
c) git fetch
d) git copy

17. What is the command to fetch changes from a remote repository without merging them?

a) git pull
b) git fetch
c) git merge
d) git update

18. How do you push your changes to a remote repository?

a) git commit
b) git push
c) git send
d) git upload

19. What is a fork in GitHub?

a) A copy of a repository in your GitHub account
b) A branch of a repository
c) A pull request
d) A reset of a branch

20. How do you pull changes from a remote repository and merge them into your local branch?

a) git fetch
b) git pull
c) git merge
d) git checkout

21. How do you delete a branch locally in Git?

a) git branch -d branch-name
b) git remove branch-name
c) git delete branch-name
d) git erase branch-name

22. What does git stash do in Git?

a) Temporarily saves uncommitted changes
b) Merges branches
c) Deletes a branch
d) Resets the repository

23. How do you list all the branches in a Git repository?

a) git list
b) git branches
c) git show-branches
d) git branch

24. How do you reset the current branch to a specific commit?

a) git revert commit-hash
b) git reset commit-hash
c) git delete commit-hash
d) git undo commit-hash

25. What is the command to undo the last commit in Git?

a) git reset --hard HEAD^
b) git revert HEAD
c) Both a and b
d) git delete HEAD

26. What is the purpose of a GitHub repository's README.md file?

a) To describe the project and provide instructions
b) To store sensitive information
c) To commit code changes
d) To manage branches

27. How do you remove a file from both the working directory and Git index?

a) git delete file
b) git rm file
c) git remove file
d) git reset file

28. What is a Git tag?

a) A label for a specific commit
b) A branch of a repository
c) A commit message
d) A pull request

29. How do you create an annotated tag in Git?

a) git tag -a tagname
b) git create tagname
c) git annotate tagname
d) git label tagname

30. How do you view the history of tags in Git?

a) git show-tags
b) git tag
c) git log --tags
d) git history

31. What is a Git remote?

a) A repository hosted on a server
b) A local branch
c) A tag
d) A commit

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

a) git add remote
b) git remote add
c) git remote new
d) git push remote

33. What is the purpose of the git diff command?

a) To display the differences between two commits
b) To switch branches
c) To reset the repository
d) To delete a branch

34. How do you rename a Git branch?

a) git rename branch new-name
b) git branch -m old-name new-name
c) git branch new-name
d) git switch branch new-name

35. What does the git log --oneline command do?

a) Displays a condensed view of the commit history
b) Shows the current branch
c) Displays the differences between commits
d) Displays the working directory status

36. How do you rebase a branch in Git?

a) git merge branch
b) git rebase branch
c) git pull branch
d) git sync branch

37. What is the difference between git pull and git fetch?

a) git pull fetches and merges changes, while git fetch only downloads changes
b) git fetch deletes remote changes, while git pull updates your repository
c) git fetch resets the repository, while git pull clones a new repository
d) Both commands do the same thing

38. How do you compare two commits in Git?

a) git diff commit1 commit2
b) git compare commit1 commit2
c) git log commit1 commit2
d) git show commit1 commit2

39. What is the purpose of git blame?

a) To show who made changes to each line of a file
b) To delete a commit
c) To reset the repository
d) To merge branches

40. What is the purpose of .gitignore?

a) To specify files and directories that Git should ignore
b) To reset the repository
c) To clone a repository
d) To view the commit history

41. What does the command git remote -v do?

a) Lists all remote repositories with URLs
b) Verifies the connection to the remote repository
c) Deletes a remote repository
d) Displays commit history from the remote repository

42. How do you undo changes in the working directory that haven’t been committed yet?

a) git revert
b) git reset --hard
c) git checkout -- file
d) git delete

43. What does the command git clean -f do?

a) Deletes untracked files from the working directory
b) Resets all staged changes
c) Resets the repository to its last commit
d) Deletes remote branches

44. How do you discard changes from the staging area in Git?

a) git remove file
b) git reset HEAD file
c) git revert HEAD file
d) git clean -f file

45. What does git reflog display?

a) A history of all reference updates
b) A list of untracked files
c) A history of all pull requests
d) A list of all merged branches

46. How do you amend the last commit in Git?

a) git commit --amend
b) git reset --amend
c) git change HEAD
d) git fix commit

47. How do you merge changes from the remote repository into your local branch?

a) git pull
b) git fetch
c) git merge
d) git commit

48. What does git cherry-pick do?

a) Applies a specific commit from one branch to another
b) Deletes a specific commit
c) Creates a new branch
d) Reverts changes made in a commit

49. What does the command git bisect do?

a) Helps find the commit that introduced a bug
b) Splits a commit into multiple parts
c) Creates a new commit
d) Shows the differences between two commits

50. How do you list all tags in a Git repository?

a) git tags
b) git tag --list
c) git tag -a
d) git list-tags

51. What does the git shortlog command do?

a) Summarizes the commit history by author
b) Displays the full commit history
c) Shows a brief log of remote changes
d) Displays file-level changes

52. What is a “detached HEAD” in Git?

a) A state where HEAD points to a commit instead of a branch
b) A corrupted branch
c) A repository without a HEAD
d) A branch without commits

53. How do you reapply commits on top of another base branch in Git?

a) git merge
b) git rebase
c) git pull
d) git cherry-pick

54. What does the git stash apply command do?

a) Applies the latest stashed changes without deleting them
b) Deletes stashed changes
c) Commits stashed changes
d) Creates a new stash

55. What does the command git pull --rebase do?

a) Fetches and rebases changes from the remote branch
b) Fetches and creates a new branch
c) Deletes remote changes
d) Creates a new commit on the remote repository

56. What does the git archive command do?

a) Creates a zip or tar archive of the repository
b) Archives old commits
c) Deletes branches
d) Shows archived commits

57. How do you view all stashes in a Git repository?

a) git stash list
b) git log --stash
c) git stash show
d) git reflog stash

58. What does the git diff --cached command show?

a) Differences between the index (staging area) and the last commit
b) Differences between working directory and the index
c) Differences between two commits
d) Differences between local and remote branches

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

a) git tag tagname commit-hash
b) git tag -m commit-hash
c) git annotate commit-hash
d) git commit -t

60. What does git push origin --tags do?

a) Pushes all tags to the remote repository
b) Pushes only the latest tag
c) Deletes remote tags
d) Pushes tags and removes untracked files

61. What does the git stash drop command do?

a) Deletes the latest stash
b) Applies the latest stash
c) Lists all stashes
d) Commits the latest stash

62. What is the command to view the commit history of a file?

a) git log filename
b) git history filename
c) git show-log filename
d) git commit-log filename

63. What does the git show command do?

a) Displays details about a specific commit
b) Shows a list of all branches
c) Shows the current branch status
d) Displays a list of stashes

64. How do you rename a file in Git?

a) git mv oldname newname
b) git rename oldname newname
c) git move oldname newname
d) git update-file oldname newname

65. What does git rm --cached do?

a) Removes a file from the staging area but keeps it in the working directory
b) Deletes a file from both the staging area and working directory
c) Moves a file to a new location
d) Reverts the last commit

66. What is a Git hook?

a) A script that runs automatically before or after Git events
b) A tool for resolving merge conflicts
c) A command to check remote branches
d) A tag for annotating commits

67. How do you resolve merge conflicts in Git?

a) Manually edit the conflicting files and commit the changes
b) Run git resolve
c) Delete the conflicting files
d) Reset the repository to a previous state

68. What is the command to list all untracked files in Git?

a) git status
b) git ls-files --others
c) git show untracked
d) git log --untracked

69. How do you squash commits in Git?

a) By using git rebase -i (interactive rebase)
b) By using git squash
c) By using git commit --squash
d) By using git combine

70. What does git revert do?

a) Creates a new commit that undoes the changes of a previous commit
b) Deletes the most recent commit
c) Resets the repository to a specific commit
d) Moves the HEAD pointer to the previous commit

71. What does the command git checkout -b branchname do?

a) Creates and switches to a new branch
b) Merges a branch
c) Deletes a branch
d) Checks out the latest commit on the main branch

72. How do you rename a Git remote?

a) git remote rename oldname newname
b) git rename remote oldname newname
c) git remote move oldname newname
d) git rename remote newname

73. What does the git fetch --prune command do?

a) Removes references to branches that no longer exist on the remote
b) Deletes all branches on the remote
c) Fetches all branches from the remote
d) Updates the current branch to match the remote

74. What does the git diff command show?

a) The differences between the working directory and the staging area
b) The commit history
c) The list of branches
d) The differences between two commits

75. How do you reset your working directory to the last commit in Git?

a) git reset --hard
b) git revert HEAD
c) git checkout --last
d) git reset HEAD

76. How do you check out a specific commit in Git?

a) git checkout commit-hash
b) git revert commit-hash
c) git checkout branch-name
d) git pull commit-hash

77. What does git blame display?

a) Shows who made changes to each line of a file
b) Shows a list of uncommitted changes
c) Shows the commit history
d) Shows all remote branches

78. What does the git describe command do?

a) Describes the most recent tag reachable from a commit
b) Shows the description of the repository
c) Adds a description to a commit
d) Lists the differences between commits

79. How do you initialize a new Git repository?

a) git init
b) git start
c) git new
d) git create

80. What does the git submodule command do?

a) Manages external repositories within a Git repository
b) Creates branches for external modules
c) Merges multiple repositories into one
d) Deletes external modules

81. What does the git show-ref command do?

a) Lists references (branches or tags) in a Git repository
b) Displays detailed information about a commit
c) Shows the current status of the working directory
d) Displays a summary of the commit history

82. How do you create an alias for a Git command?

a) git config --global alias.alias-name 'git-command'
b) git alias create alias-name
c) git alias git-command alias-name
d) git create alias alias-name

83. How do you ignore a file in Git without deleting it?

a) Add the file to .gitignore
b) Use git rm --cached filename
c) Delete the file locally
d) Use git reset filename

84. What does git push --force do?

a) Forces the remote repository to accept changes, overwriting conflicts
b) Deletes the remote branch
c) Merges a remote branch with the local branch
d) Pushes tags to the remote repository

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

a) git push origin --delete branch-name
b) git remove branch-name
c) git branch -d branch-name
d) git reset origin branch-name

86. What does the git config --list command show?

a) Displays all configuration settings
b) Shows the commit history
c) Lists all local branches
d) Displays the differences between commits

87. What does git reset --soft do?

a) Moves the HEAD pointer to a specific commit but keeps changes in the working directory
b) Deletes uncommitted changes
c) Deletes the commit history
d) Stashes changes

88. How do you view the commit history of a repository in a graph format?

a) git log --graph
b) git graph
c) git log --history
d) git show --graph

89. What does the git cherry-pick command do?

a) Applies a specific commit from one branch to another
b) Deletes a commit from the history
c) Resets the current branch to a specific commit
d) Combines multiple branches

90. How do you configure Git to use a specific text editor?

a) git config --global core.editor "editor-name"
b) git set editor editor-name
c) git edit config editor-name
d) git commit --editor editor-name

91. How do you undo the last local commit without removing the changes?

a) git reset --soft HEAD^
b) git revert HEAD^
c) git reset --hard HEAD^
d) git checkout --last

92. What does the git stash pop command do?

a) Applies the latest stashed changes and removes them from the stash list
b) Removes all stashed changes
c) Displays the list of stashes
d) Saves uncommitted changes without removing them

93. What does the git gc command do?

a) Optimizes the Git repository by cleaning up unnecessary files and compressing objects
b) Generates a commit graph
c) Commits all changes automatically
d) Deletes all untracked files

94. How do you squash commits during a rebase?

a) Use git rebase -i and mark the commits you want to squash as "squash"
b) Use git squash after rebasing
c) Use git merge --squash
d) Use git squash rebase

95. How do you create a new branch from an existing branch in Git?

a) git checkout -b new-branch
b) git branch create new-branch
c) git switch --create new-branch
d) git merge --create new-branch

96. How do you fetch all remote branches without merging them into your local branches?

a) git fetch
b) git pull --no-merge
c) git fetch --merge
d) git clone --all

97. What does git reset --hard HEAD^ do?

a) Resets the current branch to the previous commit and deletes all uncommitted changes
b) Deletes the last commit but keeps the changes in the working directory
c) Reverts the last commit and stages the changes
d) Moves the HEAD pointer to the first commit

98. How do you view the commit history with only the commit messages?

a) git log --oneline
b) git history --short
c) git log --brief
d) git log --message

99. What does git clone do?

a) Copies a remote Git repository to your local machine
b) Deletes a remote repository
c) Merges a remote repository into the current branch
d) Pushes changes to the remote repository

100. What does git config --global user.name do?

a) Sets the user’s name for all Git repositories on the system
b) Displays the current user name
c) Adds a username to the local repository
d) Configures the remote repository username

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare