Version Control - Subjective Interview Questions_document
Version Control - Subjective Interview Questions_document
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.
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.
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.
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.
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.
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.
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.
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 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.
Answer: A tag in Git is a marker used to indicate a specific point in the commit history, typically used to
mark release versions.
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.
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.
Answer: The git status command shows the current status of your working directory, including changes that
are staged, unstaged, or untracked.
Answer: The git diff command shows the differences between the working directory and the last commit, or
between two branches, files, or commits.
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.
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.
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.
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.
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.
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.
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.
Answer: To push changes to a remote repository, use the git push command:
Answer: The git cherry-pick command is used to apply the changes from a specific commit in another
branch to the current branch.
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.
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 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.
Answer: You can create a new Git repository by running the following command:
git init
Answer: git config is used to set Git configuration values such as user name, email, default editor, and other
repository or global settings.
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.
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.
Answer: You can switch branches in Git using the following command:
git checkout branch_name
Answer: The git ls-files command lists all files that are currently being tracked by Git in the repository.
Answer: You can create an empty commit by using the following command:
git commit --allow-empty -m "Empty commit message"
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.
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.
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.
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)
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
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 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.
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.
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.
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.
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
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
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.
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).
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.
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.
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.
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.
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: 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.
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
Answer: A Git remote is a reference to a remote repository, allowing you to push and pull changes to and
from it.
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: 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.
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.
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.
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?
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
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?
Question 105: How do you see the differences between two commits?
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.
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.