Top 50 Version Control Systems Interview Question and Answers
1. What is a Version Control System (VCS)?
- Answer: A VCS is a tool that helps manage changes to source code or files, tracking history, merging updates, and enabling collaboration.
2. Why use Version Control Systems?
- Answer: To keep track of code changes, collaborate with team members, revert to previous versions, and maintain a history of changes.
3. What are the types of Version Control Systems?
-
Answer:
- Centralized VCS: e.g., SVN, where all version history is stored in a central server.
- Distributed VCS: e.g., Git, where each developer has a full copy of the repository.
4. What is Git?
- Answer: Git is a distributed VCS that is widely used for tracking changes in source code during software development.
5. How is Git different from SVN?
- Answer: Git is distributed, allowing each developer to have a full repository copy, while SVN is centralized.
6. What is a repository in Git?
- Answer: A repository is a storage location for your project’s files, including the complete history of changes.
7. What is a commit in Git?
- Answer: A commit is a snapshot of the project’s changes at a specific point in time, stored in the repository.
8. What does git init
do?
- Answer: Initializes a new Git repository in the current directory.
9. How do you check the status of your Git repository?
-
Answer: By running
git status
.
10. What is a branch in Git?
-
Answer: A branch is a parallel line of development.
master
ormain
is the default branch.
11. What is the purpose of branches?
- Answer: To isolate code changes for features, bug fixes, or experiments, allowing developers to work independently.
12. How do you create a new branch?
-
Answer:
git branch branch_name
13. How do you switch to another branch?
-
Answer:
git checkout branch_name
orgit switch branch_name
14. How do you create and switch to a new branch in one command?
-
Answer:
git checkout -b branch_name
15. What is git merge
?
- Answer: Combines changes from one branch into another branch.
16. What are merge conflicts?
- Answer: Occur when changes in different branches clash and need manual resolution.
17. How do you resolve a merge conflict in Git?
-
Answer: Open the conflicting files, manually resolve conflicts, and then
git add
the resolved files.
18. What is git rebase
?
- Answer: Reapplies commits on top of another base tip, providing a cleaner project history.
19. When would you use git rebase
instead of git merge
?
-
Answer: Use
git rebase
to maintain a linear project history.
20. What does git pull
do?
- Answer: Fetches changes from a remote repository and merges them into the current branch.
21. What does git fetch
do?
- Answer: Downloads changes from a remote repository but does not merge them into your local branch.
22. How do you push changes to a remote repository?
-
Answer:
git push origin branch_name
23. What is a remote repository?
- Answer: A version of your project hosted on the internet or a network for collaboration.
24. What is git clone
used for?
- Answer: Creates a local copy of a remote repository.
25. How do you remove a file from the staging area without deleting it from the working directory?
-
Answer:
git reset HEAD file_name
26. How do you view the commit history?
-
Answer:
git log
27. What is git stash
used for?
- Answer: Temporarily saves uncommitted changes, cleaning the working directory.
28. How do you apply stashed changes?
-
Answer:
git stash apply
29. How do you delete a branch in Git?
-
Answer:
git branch -d branch_name
for a merged branch;git branch -D branch_name
for an unmerged branch.
30. What is .gitignore
?
- Answer: A file that specifies intentionally untracked files to ignore.
31. What is git diff
?
- Answer: Shows differences between files in the working directory and the index or a commit.
32. What does git reset
do?
- Answer: Undoes changes by moving the HEAD to a specified state, modifying the staging area and working directory.
33. What is git cherry-pick
?
- Answer: Applies a specific commit from one branch onto another.
34. What is git tag
?
- Answer: Used to mark specific points in history as important, usually for releases.
35. What is a fork in GitHub?
- Answer: A copy of a repository that allows you to freely experiment with changes without affecting the original.
36. How do you undo the last commit without losing changes?
-
Answer:
git reset --soft HEAD~1
37. How do you revert a specific commit?
-
Answer:
git revert commit_hash
38. What is git blame
?
- Answer: Shows who made changes to each line in a file and when.
39. How do you squash commits in Git?
-
Answer: Use
git rebase -i HEAD~n
and choose the squash option for commits to combine.
40. What is git bisect
?
- Answer: A tool to find the commit that introduced a bug using binary search.
41. What is a submodule in Git?
- Answer: A repository embedded inside another repository.
42. How do you initialize and update Git submodules?
-
Answer:
git submodule init
andgit submodule update
43. How do you remove a file from the Git repository but not from the filesystem?
-
Answer:
git rm --cached file_name
44. What is git reflog
?
- Answer: A history of all changes made to the tip of branches and references.
45. How do you rename a branch in Git?
-
Answer:
git branch -m old_branch_name new_branch_name
46. What is git gc
?
- Answer: A command to clean up unnecessary files and optimize the repository.
47. What is a hook in Git?
- Answer: Scripts that run before or after specific events, like committing or pushing.
48. What is git clean
?
- Answer: Deletes untracked files from the working directory.
49. What is the difference between git reset
and git revert
?
-
Answer:
git reset
undoes changes by moving the HEAD, whilegit revert
creates a new commit to undo changes.
50. How do you revert multiple commits in one go?
-
Answer: Use
git revert commit_hash1 commit_hash2 ...
orgit revert HEAD~n..HEAD
for a range.