0% found this document useful (0 votes)
8 views11 pages

Version Control - Subjective Interview Questions_document

The document contains a comprehensive list of interview questions and answers related to version control, specifically focusing on Git. Key topics include the definition of version control, Git functionalities, commands, and concepts such as branches, commits, merges, and workflows. It serves as a valuable resource for understanding Git and its application in collaborative software development.

Uploaded by

vodnala srujana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Version Control - Subjective Interview Questions_document

The document contains a comprehensive list of interview questions and answers related to version control, specifically focusing on Git. Key topics include the definition of version control, Git functionalities, commands, and concepts such as branches, commits, merges, and workflows. It serves as a valuable resource for understanding Git and its application in collaborative software development.

Uploaded by

vodnala srujana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Edunet Foundation

Interview Questions – Version Control

Question 1: What is version control?

Answer: Version control is a system that allows developers to track and manage changes to a project's
codebase over time, enabling collaboration, rollback to previous versions, and maintaining history.

Question 2: What is Git?

Answer: Git is a distributed version control system that allows multiple developers to track and manage
changes to source code. It is commonly used for version control in software development.

Question 3: What is the difference between Git and SVN?

Answer: Git is a distributed version control system, meaning each developer has a full copy of the
repository, while SVN (Subversion) is a centralized version control system, meaning the repository is stored
in a central server.

Question 4: What is a commit in Git?

Answer: A commit is a snapshot of the project at a particular point in time. It saves changes made to the files
in the Git repository.

Question 5: What is the purpose of a branch in Git?

Answer: A branch in Git allows developers to work on different features or fixes independently of the main
codebase (usually the main or master branch). It enables parallel development without affecting the stability
of the main branch.

Question 6: What is the difference between git merge and git rebase?

Answer: git merge combines two branches together, keeping the commit history intact. git rebase applies
changes from one branch on top of another, rewriting the commit history to create a linear progression of
commits.

Question 7: What is a pull request (PR)?

Answer: A pull request is a way to propose changes to a project. After making changes in a branch, a
developer can create a pull request to merge their changes into the main project branch. It allows team
members to review the code before merging.

Question 8: What is the purpose of .gitignore?

Answer: The .gitignore file tells Git which files or directories to ignore in version control. It is typically used
to exclude temporary files, build artifacts, or sensitive information from being committed.

Question 9: What is a clone in Git?

Answer: Cloning in Git refers to creating a copy of an existing repository. The git clone command is used to
create a local copy of a remote repository, allowing you to work on it locally.

Question 10: What is a remote repository in Git?


Answer: A remote repository is a version of your project that is hosted on a server or cloud service, such as
GitHub or GitLab. It allows multiple developers to collaborate on the project by pushing and pulling
changes.

Question 11: What is the difference between git fetch and git pull?

Answer: git fetch retrieves changes from a remote repository but does not merge them into your working
directory. git pull fetches changes and merges them into the current branch.

Question 12: What is a tag in Git?

Answer: A tag in Git is a marker used to indicate a specific point in the commit history, typically used to
mark release versions.

Question 13: What is a fork in Git?

Answer: A fork is a copy of a repository that allows you to make changes without affecting the original
project. Forks are commonly used in open-source projects to propose changes or contribute.

Question 14: What is the git log command used for?

Answer: The git log command is used to display the commit history of a repository, showing detailed
information about each commit such as the commit message, author, and date.

Question15: What is the git status command used for?

Answer: The git status command shows the current status of your working directory, including changes that
are staged, unstaged, or untracked.

Question16: What is the git diff command used for?

Answer: The git diff command shows the differences between the working directory and the last commit, or
between two branches, files, or commits.

Question 17: What is the git stash command used for?

Answer: The git stash command temporarily saves changes that are not ready to be committed, allowing you
to switch branches or work on something else without losing progress.

Question 18: What is the purpose of git rebase?

Answer: The git rebase command is used to integrate changes from one branch onto another, creating a
cleaner and linear history. It can be used to update a feature branch with the latest changes from the main
branch.

Question 19: What is a Git workflow?

Answer: A Git workflow defines a set of guidelines and processes for using Git in a collaborative
development environment. Common workflows include centralized workflows, feature branch workflows,
Gitflow, and forking workflows.

Question 20: What is a merge conflict?

Answer: A merge conflict occurs when two branches have changes in the same part of a file, and Git is
unable to automatically merge them. It requires manual intervention to resolve the conflict.
Question 21: How do you resolve a merge conflict in Git?

Answer: To resolve a merge conflict in Git, open the conflicting files and choose which changes to keep,
then remove the conflict markers. After resolving the conflict, stage the changes and commit the merge.

Question 22: What is git blame used for?

Answer: The git blame command shows the author of each line in a file, allowing you to see who made
changes to specific lines of code.

Question 23: How to undo a commit in Git?

Answer: You can undo a commit by using the git reset command. For example, git reset --soft HEAD~1 will
undo the last commit but keep the changes in your working directory.

Question 24: What is the git revert command used for?

Answer: The git revert command is used to create a new commit that undoes the changes made by a previous
commit. Unlike git reset, git revert does not modify the commit history.

Question 25: How do you push changes to a remote repository in Git?

Answer: To push changes to a remote repository, use the git push command:

git push origin branch_name

Question 26: What is the git cherry-pick command used for?

Answer: The git cherry-pick command is used to apply the changes from a specific commit in another
branch to the current branch.

Question 27: What is a commit message convention in Git?

Answer: Commit message conventions are standardized rules for writing clear and consistent commit
messages. A common format is:
• Subject Line: Brief and descriptive (imperative mood)
• Body: Detailed explanation of the changes, if necessary
• Footer: Issue tracker references or breaking changes.

Question 28: What is git reset used for?

Answer: git reset is used to undo changes in Git. It can be used to unstage changes, revert to a previous
commit, or remove commits from the history.

Question 29: What is the difference between git pull and git fetch?

Answer: git fetch retrieves changes from a remote repository without merging them, while git pull fetches
changes and automatically merges them into your current branch.

Question 30: How to create a new branch in Git?

Answer: To create a new branch in Git, use:


git branch new_branch_name

Question 31: What is the difference between git push and git pull?
Answer: git push is used to upload local repository content to a remote repository, while git pull fetches
changes from the remote repository and merges them into the current local branch.

Question 32: How do you create a new Git repository?

Answer: You can create a new Git repository by running the following command:
git init

Question 33: What is git config used for?

Answer: git config is used to set Git configuration values such as user name, email, default editor, and other
repository or global settings.

Question 34: How do you view your Git configuration?

Answer: To view your Git configuration, use the command:


git config --list

Question 35: What is the difference between git clone and git fork?

Answer: git clone creates a local copy of a remote repository, whereas git fork creates a personal copy of
someone else’s repository on GitHub or a similar platform, allowing independent changes without affecting
the original repository.

Question 36: What does git commit --amend do?


Answer: git commit --amend allows you to modify the most recent commit, either by updating the commit
message or including additional changes in the commit.

Question 37: What is a GitHub Pull Request (PR) review process?

Answer: A pull request review process allows team members to review, discuss, and provide feedback on
changes proposed in a pull request before merging it into the main branch.

Question 38: How do you switch branches in Git?

Answer: You can switch branches in Git using the following command:
git checkout branch_name

Question 39: What is the git ls-files command used for?

Answer: The git ls-files command lists all files that are currently being tracked by Git in the repository.

Question 40: How do you create an empty commit in Git?

Answer: You can create an empty commit by using the following command:
git commit --allow-empty -m "Empty commit message"

Question 41: What is the purpose of git commit --no-verify?

Answer: git commit --no-verify skips pre-commit and commit-msg hooks, allowing you to bypass any
checks or validations defined in the repository's Git hooks.

Question 42: What is the difference between git pull and git fetch?

Answer: git fetch retrieves the latest changes from the remote repository, but it does not merge them into
your local branch. git pull fetches the latest changes and merges them into your current branch.
Question 43: What is the purpose of the .gitmodules file in Git?

Answer: The .gitmodules file is used to track submodules in a Git repository. It contains information about
the location of the submodule repository and its settings.

Question 44: How do you undo a pushed commit?

Answer: To undo a pushed commit, you can use git revert to create a new commit that undoes the changes of
the pushed commit. Alternatively, you can use git reset (with caution) to reset to a previous commit, but this
can rewrite history and should be avoided if others are working with the same branch.

Question 45: What is a detached HEAD state in Git?

Answer: A detached HEAD state occurs when the HEAD points to a specific commit rather than a branch. In
this state, changes made are not associated with any branch, and if you switch branches, they may be lost
unless explicitly saved.

Question 46: What is the difference between git stash and git commit?

Answer: git stash temporarily saves uncommitted changes in a separate stack, allowing you to work on
something else. git commit records changes in the Git history with a commit message, saving them as part of
the repository's history.

Question 47: What is Git Flow?

Answer: Git Flow is a branching model for Git that defines a strict branching structure to manage releases,
features, and hotfixes. It uses branches like master, develop, feature, release, and hotfix to organize
development workflows.

Question 48: What is the difference between git pull --rebase and git pull?

Answer: git pull fetches and merges changes from the remote branch, creating a merge commit. git pull --
rebase fetches the changes and rebases them onto your local commits, making the history linear without
creating a merge commit.

Question 49: How can you list all the branches in your Git repository?

Answer: You can list all the branches in your Git repository by running:
git branch (for local branches)
git branch -r (for remote branches)
git branch -a (for all branches)

Question 50: How do you ignore files globally in Git?

Answer: To ignore files globally in Git, create a global .gitignore file (usually in your home directory) and
then configure Git to use it by running:
git config --global core.excludesfile ~/.gitignore_global

Question 51: What is the purpose of git reflog?

Answer: git reflog is used to view the history of changes to the HEAD and the current branch, including
actions like checkouts, commits, resets, and merges. It allows you to recover lost commits that are not
reachable by the branch history.

Question 52: How do you push a specific branch to a remote repository?


Answer: To push a specific branch to a remote repository, use:
git push origin branch_name

Question 53: How do you delete a remote branch in Git?

Answer: To delete a remote branch, use:


git push origin --delete branch_name

Question 54: How do you delete a local branch in Git?

Answer: To delete a local branch, use:


git branch -d branch_name (for a safe delete)
git branch -D branch_name (force delete, even if unmerged)

Question 55: What is the difference between git reset and git checkout?
Answer: git reset is used to move the HEAD and index to a previous commit, optionally changing the
working directory. git checkout is used to switch branches or restore files in your working directory from the
commit history.

Question 56: What is the difference between git commit --amend and git reset HEAD~1?

Answer: git commit --amend modifies the most recent commit, allowing you to add or modify changes. git
reset HEAD~1 removes the most recent commit, but it doesn’t alter the working directory or staged changes.

Question 57: What is the purpose of git clean?

Answer: git clean is used to remove untracked files or directories from the working directory. It can be
useful for cleaning up temporary files or build artifacts that are not being tracked by Git.

Question 58: How do you compare two branches in Git?

Answer: You can compare two branches in Git using:


git diff branch1..branch2
This will show the differences between the two branches.

Question 59: What is the purpose of git archive?

Answer: git archive is used to create an archive (such as a .zip or .tar file) of the contents of a specific
commit or branch, excluding the .git directory.

Question 60: What is a submodule in Git?

Answer: A submodule is a Git repository embedded within another Git repository. It allows you to include
external repositories as part of your project while keeping them separate from the main repository.

Question 61: What is git bisect used for?

Answer: git bisect is used to find the commit that introduced a bug. It performs a binary search through the
commit history to identify the commit that caused the issue.

Question 62: How do you remove files from the staging area?

Answer: To remove files from the staging area without deleting them, use:
git reset HEAD file_name

Question 63: What is the purpose of git rm?


Answer: git rm is used to remove files from both the working directory and the staging area. It is equivalent
to using rm in the terminal followed by git add to untrack the file.

Question 64: How can you set up a Git alias?

Answer: To create a Git alias, you can modify your Git configuration file. For example, to create an alias for
git status, use:
git config --global alias.st status

Question 65: What is git merge --no-ff?

Answer: git merge --no-ff ensures that a merge commit is always created, even if the merge could be fast-
forwarded. This is useful for keeping the history of feature branches.

Question 66: What does the git ls-tree command do?

Answer: git ls-tree shows the contents of a tree object (like a commit or branch) and displays files and
directories within the given commit, including the object type (blob for files, tree for directories).

Question 67: What is a fast-forward merge in Git?

Answer: A fast-forward merge occurs when the current branch’s head is directly behind the branch being
merged into it, meaning there are no divergent commits. Git simply moves the branch pointer forward
without creating a merge commit.

Question 68: What is the difference between git push and git fetch?

Answer: git push sends your local commits to a remote repository, while git fetch retrieves changes from the
remote repository but does not merge them into your local branch.

Question 69: How do you change the author of a commit in Git?

Answer: You can change the author of the most recent commit using:
git commit --amend --author="New Author <new.email@example.com>"

Question 70: What is the difference between git diff and git status?

Answer: git diff shows the changes between the working directory and the index, or between commits. git
status shows the current state of the working directory and the staging area, including changes that have been
staged, modified, or untracked.

Question 71: What does git diff show?

Answer: git diff shows the differences between the working directory and the staging area or between
different commits, helping you see what changes have been made.

Question 72: What is the purpose of git merge --no-ff?

Answer: The git merge --no-ff option forces a merge commit even if the merge could be performed with a
fast-forward, maintaining a clear commit history.

Question 73: How can you list the commits made by a specific author in Git?

Answer: You can list commits by a specific author using the following command:
git log --author="author_name"
Question 74: What does git tag do?

Answer: git tag is used to create a tag for a specific commit, marking it as a milestone, release, or version.
Tags are often used to mark release points like v1.0 or v2.0.

Question 75: What is the difference between a lightweight and annotated tag in Git?

Answer: A lightweight tag is a simple reference to a commit, while an annotated tag is a full object in the Git
database, containing the tagger’s name, email, date, and message.

Question 76: How do you remove a tag in Git?

Answer: To remove a tag locally, use the following command:


git tag -d tag_name
To remove it remotely, use:
git push --delete origin tag_name

Question 77: What is the git fetch command used for?

Answer: git fetch downloads objects and refs from another repository without modifying the working
directory or merging changes, allowing you to review the changes before applying them.

Question 78: What is the difference between git pull --rebase and git merge?

Answer: git pull --rebase applies your local commits on top of the changes fetched from the remote
repository, maintaining a linear history, while git merge combines the two branches, often resulting in a
merge commit.

Question 79: What does the command git show <commit_id> do?

Answer: git show <commit_id> displays the details of a specific commit, including the commit message,
author, date, and the changes made in that commit.

Question 80: How can you list all tags in a Git repository?

Answer: To list all tags, use the command:


git tag

Question 81: What is the git pull --ff-only option?

Answer: The git pull --ff-only option ensures that the pull operation will only succeed if the merge can be
performed with a fast-forward, meaning there will be no merge commit.

Question 82: How do you move a file from one directory to another in Git while keeping it tracked?

Answer: You can move a file to another directory using the following command:
git mv old_file_path new_file_path
Then commit the change.

Question 83: What is git blame used for?

Answer: git blame shows who last modified each line of a file, along with the commit hash and timestamp,
useful for tracking down the origin of specific changes.

Question 84: How can you revert a file to a previous version in Git?
Answer: To revert a file to a previous version, use the following command:
git checkout commit_hash -- file_name

Question 85: How can you temporarily store changes without committing them?

Answer: You can temporarily store changes using git stash, which saves your working directory changes and
reverts it to the last commit.

Question 86: How do you remove a file from version control but keep it in the working directory?

Answer: To remove a file from version control but leave it in the working directory, use:
git rm --cached file_name

Question 87: How can you see which files are being tracked by Git?

Answer: You can see which files are being tracked by Git by using:
git ls-files

Question 88: What is the purpose of a Git remote?

Answer: A Git remote is a reference to a remote repository, allowing you to push and pull changes to and
from it.

Question 89: What is the purpose of git merge --squash?

Answer: git merge --squash combines all changes from a branch into a single commit, squashing multiple
commits into one when merging.

Question 90: How do you view all branches, both local and remote?

Answer: To view all branches, both local and remote, use:


git branch -a

Question 91: What is a detached HEAD in Git?

Answer: A detached HEAD occurs when you are not on a branch but instead on a specific commit. This
means any commits made in this state will not be associated with any branch unless explicitly created or
moved to an existing branch.

Question 92: What is the git pull command?

Answer: git pull is used to fetch changes from the remote repository and automatically merge them into your
local branch, combining git fetch and git merge in one command.

Question 93: How do you clone a repository from GitHub?

Answer: To clone a repository from GitHub, use the command:


git clone https://github.com/username/repository.git

Question 94: What does the git clean command do?

Answer: git clean removes untracked files and directories from the working directory. It's useful for cleaning
up files that are not tracked by Git, such as build artifacts.

Question 95: How do you list all commits on a specific branch?


Answer: To list all commits on a specific branch, use the command:
git log branch_name

Question 96: What does git checkout <branch_name> do?

Answer: git checkout <branch_name> switches the working directory to the specified branch, updating the
files and history to match that branch.

Question 97: How do you change the commit message of the last commit?

Answer: To change the commit message of the last commit, use:


git commit --amend

Question 98: What is the difference between git merge and git rebase?

Answer: git merge combines two branches by creating a new merge commit, while git rebase moves or
combines commits from one branch onto another, resulting in a linear history without merge commits.

Question 99: How do you see the commit history in a graphical format?

Answer: To view the commit history in a graphical format, you can use:
git log --graph --oneline

Question 100: What is the purpose of the git cherry-pick command?

Answer: git cherry-pick applies the changes from a specific commit from another branch onto your current
branch, creating a new commit with those changes.

Question 101: What is the difference between git diff and git log?

Answer: git diff shows the differences between the working directory and staging area or between commits,
while git log shows the commit history of the repository.

Question 102: How do you fetch updates from a specific remote repository?

Answer: To fetch updates from a specific remote repository, use:


git fetch remote_name

Question 103: How do you list all remote repositories in Git?

Answer: To list all remote repositories, use:


git remote -v

Question 104: What is the purpose of git fetch --all?


Answer: git fetch --all fetches updates from all remote repositories configured in the local Git repository.

Question 105: How do you see the differences between two commits?

Answer: To see the differences between two commits, use:


git diff commit1 commit2

Question 106: What is a "fork" in Git and GitHub?

Answer: A "fork" is a copy of a repository that allows you to make changes without affecting the original
project. It's often used for contributing to open-source projects.
Question 107: What is the purpose of git remote add?

Answer: git remote add is used to add a remote repository URL to your local repository configuration,
allowing you to fetch, pull, or push changes to/from that remote.

Question 108: How can you create an empty Git repository?

Answer: You can create an empty Git repository with the following command:
git init

Question 109: What is the difference between git pull and git fetch?

Answer: git pull fetches changes from a remote repository and merges them into the current branch, while git
fetch only fetches the changes but does not automatically merge them.

Question 110: How do you view the contents of a specific commit?

Answer: To view the contents of a specific commit, use:


git show commit_id

You might also like