Debug School

Akanksha
Akanksha

Posted on

Top 30 GIT Interview Questions with Answers

1. What is Git?

a) A version control system
b) A programming language
c) An operating system
d) A text editor
Answer: a

2. What is the purpose of version control?

a) To track changes in code
b) To compile code
c) To write documentation
d) To design user interfaces
Answer: a

3. Which command is used to initialize a Git repository in a directory?

a) git clone
b) git init
c) git commit
d) git push
Answer: b

4. What is the command to stage changes for commit in Git?

a) git push
b) git commit -m
c) git add
d) git status
Answer: c

5. What is the purpose of the "git commit" command?

a) To stage changes
b) To create a new branch
c) To add files to the repository
d) To record changes in the repository
Answer: d

6. Which command is used to create a new branch in Git?

a) git checkout
b) git branch
c) git merge
d) git commit
Answer: b

7. How can you switch to a different branch in Git?

a) git branch
b) git merge
c) git checkout
d) git commit
Answer: c

8. What does "git pull" do?

a) Pushes changes to a remote repository
b) Deletes a branch
c) Fetches changes from a remote repository and merges them into the current branch
d) Resets the repository to an earlier state
Answer: c

9. What does "git push" do?

a) Fetches changes from a remote repository
b) Deletes a branch
c) Pushes changes to a remote repository
d) sets the repository to an earlier state
Answer: c

10. How do you create a copy of a Git repository on your local machine?

a) git clone
b) git pull
c) git branch
d) git commit
Answer: a

11. What is a Git remote?

a) A local copy of a repository
b) A branch in your local repository
c) A separate repository that your repository can interact with
d) A type of merge operation
Answer: c

12. Which Git command is used to see the history of commits in a repository?

a) git log
b) git diff
c) git status
d) git fetch
Answer: a

13. How do you discard changes in your working directory in Git?

a) git commit
b) git push
c) git reset
d) git branch
Answer: c

14. What is a Git merge conflict?

a) A conflict that occurs when you try to create a new branch
b) A conflict that occurs when you try to push changes to a remote repository
c) A conflict that occurs when Git cannot automatically merge changes from different branches
d) A conflict that occurs when you try to delete a branch
Answer: c

15. How can you resolve a Git merge conflict?

a) Delete one of the conflicting branches
b) Use the "git conflict" command
c) Manually edit the conflicted files and then commit the changes
d) Wait for Git to resolve it automatically
Answer: c

16. What is the purpose of the .gitignore file in a Git repository?

a) To specify which files and directories should be included in the repository
b) To specify which files and directories should be ignored by Git
c) To track changes to the repository's configuration
d) To create a backup of the repository
Answer: b

17. What is the difference between "git pull" and "git fetch"?

a) There is no difference; they are the same command
b) "git pull" fetches changes and merges them, while "git fetch" only fetches changes
c) "git fetch" fetches changes and merges them, while "git pull" only fetches changes
d) "git pull" and "git fetch" are not Git commands
Answer: b

18. How can you undo the last Git commit?

a) git reset --soft HEAD^
b) git revert HEAD
c) git commit --undo
d) git reset --hard HEAD^
Answer: a

19. What is the purpose of the "git rebase" command?

a) To merge a branch into the current branch
b) To apply changes from one branch onto another branch
c) To create a new branch
d) To delete a branch
Answer: b

20. What is the difference between "git merge" and "git rebase"?

a) There is no difference; they are the same command
b) "git merge" creates a new branch, while "git rebase" merges changes from one branch onto another
c) "git merge" merges changes from one branch onto another, while "git rebase" creates a new branch
d) "git merge" is used to resolve conflicts, while "git rebase" is used to create new branches
Answer: c

21. What is a Git tag used for?

a) To label specific commits as important points in the project's history
b) To mark files as read-only
c) To merge two branches
d) To delete branches
Answer: a

22. What is Git's "HEAD"?

a) The main branch of a repository
b) A reference to the latest commit in the current branch
c) The name of a remote repository
d) A command to create a new branch
Answer: b

23. How do you create a new branch and switch to it in a single Git command?

a) git branch
b) git checkout -b
c) git merge
d) git commit -m
Answer: b

24. What does the "git stash" command do?

a) Deletes all changes in the working directory
b) Temporarily saves changes that are not ready for a commit
c) Creates a new branch
d) Pushes changes to a remote repository
Answer: b

25. What is the purpose of the "git cherry-pick" command?

a) To remove a commit from the history
b) To merge all changes from one branch into another
c) To apply a specific commit from one branch onto another
d) To revert all changes in a branch
Answer: c

26. What is a Git submodule?

a) A separate repository that is a part of another repository
b) A branch with a unique name
c) A copy of a remote repository on your local machine
d) A branch that is not connected to any remote repository
Answer: a

27. How do you delete a branch in Git?

a) git branch -delete branch_name
b) git delete branch_name
c) git remove branch_name
d) git branch -d branch_name
Answer: d

28. What is the purpose of "git log" with the "--oneline" option?

a) To display a detailed commit history
b) To display a one-line summary of commit history
c) To display a list of remote branches
d) To display a list of local branches
Answer: b

29. What is the difference between "git pull" and "git rebase" in terms of commit history?

a) "git pull" retains the original commit history, while "git rebase" rewrites the commit history
b) "git pull" rewrites the commit history, while "git rebase" retains the original commit history
c) Both "git pull" and "git rebase" rewrite the commit history
d) Neither "git pull" nor "git rebase" affects the commit history
Answer: a

30. How do you change the commit message of the last commit in Git?

a) Use the "git commit --message" command
b) Use the "git commit --amend" command
c) Use the "git commit --change" command
d) Create a new commit with the desired message
Answer: b

31. What is a Git hook?

a) A tool for resolving merge conflicts
b) A script that runs at certain points in the Git workflow
c) A branch with a unique name
d) A remote repository
Answer: b

Top comments (0)