Git Version Control Interview Questions

Checkout Vskills Interview questions with answers in Git Version Control to prepare for your next job role. The questions are submitted by professionals to help you to prepare for the Interview.

Q.1 How do you update Git submodules in your project?
Use the git submodule update --remote command to fetch and update the submodules in your project.
Q.2 How do you show the changes made in a specific Git commit?
Use git show followed by the commit hash to display the changes, including the commit message and modified files.
Q.3 How do you revert a Git commit?
Use the git revert command followed by the commit hash to create a new commit that undoes the changes introduced by the specified commit.
Q.4 What is "Git rebase," and how does it differ from merging?
Git rebase moves a branch's commit history to a different base commit, resulting in a linear history, while merging combines changes from two branches into a new commit.
Q.5 How do you create a new branch and switch to it in Git?
Use the git checkout -b command followed by the branch name to create a new branch and switch to it in one step.
Q.6 What is "Git pull request," and how is it used for collaboration?
A pull request is a feature in Git hosting platforms like GitHub and GitLab, allowing contributors to propose changes for review and merging.
Q.7 How do you revert a Git commit without creating a new commit?
Use the git reset command followed by the --soft option and the commit hash to move the branch pointer to a previous commit without creating a new commit.
Q.8 How do you configure your Git username and email?
Use the git config command with the --global flag to set your username and email globally for all Git repositories on your machine.
Q.9 What is "Git pull" and how does it differ from "Git fetch"?
Git pull is a combination of git fetch and git merge that fetches changes and automatically merges them into the current branch. Git fetch only retrieves changes without merging.
Q.10 How do you delete a remote branch in Git?
Use the git push origin --delete command followed by the branch name to delete a remote branch.
Q.11 What is "Git rebase interactive" and how is it useful?
Interactive rebase (git rebase -i) allows you to interactively edit, squash, reword, or reorder commits during the rebase operation.
Q.12 How do you create a Git branch from a specific commit?
Use the git branch command followed by the branch name and the commit hash to create a branch from a specific commit.
Q.13 What is "Git cherry-pick," and when is it used?
Cherry-picking involves selecting specific commits from one branch and applying them to another branch.
Q.14 What is Git?
Git is a distributed version control system used for tracking changes in source code during software development.
Q.15 Explain the difference between Git and SVN.
Git is distributed, while SVN is centralized. Git provides local repositories, and SVN relies on a central server.
Q.16 What is a "repository" in Git?
A repository is a data structure that stores the version history and files of a project being managed by Git.
Q.17 What is the "working directory" in Git?
The working directory is the directory on your local machine where you edit and manipulate project files.
Q.18 What is the "staging area" (or "index") in Git?
The staging area is an intermediate step where changes are prepared before they are committed to the repository.
Q.19 How do you create a new Git repository?
Use the git init command to create a new Git repository in an existing directory.
Q.20 What is the purpose of the .git directory in a Git repository?
The .git directory contains all the metadata and version history of a Git repository.
Q.21 How do you add changes to the staging area in Git?
Use the git add command followed by the filenames or paths of the changes you want to stage.
Q.22 How do you commit changes in Git?
Use the git commit command to commit the staged changes along with a commit message describing the changes.
Q.23 What is a "commit message" in Git, and why is it important?
A commit message is a description of the changes made in a commit. It's important for tracking and understanding changes.
Q.24 How do you view the commit history in Git?
Use the git log command to view the commit history, which shows details like commit messages, authors, and timestamps.
Q.25 How do you create a new branch in Git?
Use the git branch command followed by the branch name to create a new branch.
Q.26 How do you switch between Git branches?
Use the git checkout command followed by the branch name to switch to a different branch.
Q.27 How do you merge one branch into another in Git?
Use the git merge command to merge changes from one branch into another, typically the current branch.
Q.28 What is a "conflict" in Git, and how is it resolved?
A conflict occurs when Git can't automatically merge changes. Resolving conflicts involves manual intervention.
Q.29 How do you discard changes in your working directory in Git?
Use the git checkout command with the path to the file to discard changes made since the last commit.
Q.30 What is a "remote" in Git?
A remote is a repository hosted on a server or another location, allowing collaboration and fetching changes.
Q.31 How do you add a remote repository in Git?
Use the git remote add command followed by a name and URL to add a remote repository to your local repository.
Q.32 How do you fetch changes from a remote repository in Git?
Use the git fetch command to retrieve changes from a remote repository without merging them into your current branch.
Q.33 How do you pull changes from a remote repository in Git?
Use the git pull command to fetch and merge changes from a remote repository into your current branch.
Q.34 How do you push changes to a remote repository in Git?
Use the git push command followed by the remote name and branch name to upload your changes to a remote repository.
Q.35 What is "Git clone," and how is it used?
Git clone creates a copy of a remote repository on your local machine, allowing you to work on the project locally.
Q.36 How do you create a Git tag, and what is its purpose?
Use the git tag command to create a tag for a specific commit. Tags are often used to mark release points in the history.
Q.37 How do you delete a branch in Git?
Use the git branch -d command to delete a branch locally and git push origin --delete to delete it remotely.
Q.38 What is "Gitignore," and why is it used?
A .gitignore file specifies files or directories that should be ignored by Git, such as build artifacts or log files.
Q.39 How do you create a Gitignore file?
Create a file named .gitignore in your project's root directory and list the files or patterns to be ignored.
Q.40 How do you rename a file in Git while preserving its history?
Use the git mv command to rename a file, and Git will track the renaming as part of the file's history.
Q.41 How do you undo the last Git commit?
Use the git reset HEAD~1 command to undo the last commit while keeping the changes in your working directory.
Q.42 What is "Git branching strategy," and why is it important?
A branching strategy defines how branches are used for development, providing structure and organization to the workflow.
Q.43 What is "rebasing" in Git, and when is it used?
Rebasing involves moving or combining a series of commits onto a new base commit. It's used to maintain a linear commit history.
Q.44 How do you create a Git alias for frequently used commands?
Use the git config command to define aliases in your Git configuration file (.gitconfig) for convenience.
Q.45 What is "Git bisect," and how is it used?
Git bisect is a debugging technique to find the commit that introduced a bug by performing a binary search through commits.
Q.46 How do you amend the last Git commit message?
Use the git commit --amend command followed by the -m flag and the corrected message to amend the last commit message.
Q.47 What is the purpose of the "Git stash" command?
The git stash command temporarily saves changes in the working directory to a "stash" so you can switch branches or apply changes later.
Q.48 How do you apply stashed changes in Git?
Use the git stash apply command to apply the most recent stash, or specify a stash by its name or index.
Q.49 How do you permanently delete a Git branch?
Use the git branch -d command to delete a branch locally and git push origin --delete to delete it remotely.
Q.50 What is "Git rebase -i," and how is it used?
Interactive rebasing (git rebase -i) allows you to interactively edit, squash, reword, or reorder commits during the rebase operation.
Q.51 How do you create a Git tag for a specific commit?
Use the git tag command followed by the commit's hash or a branch name to create a tag pointing to that commit.
Q.52 What is "Git cherry-pick," and how is it used?
Cherry-picking involves selecting specific commits from one branch and applying them to another branch.
Q.53 What is "Git reflog," and why is it useful?
Git reflog is a history of all reference updates, including branch creations and commits, helpful for recovering lost changes.
Q.54 How do you squash multiple Git commits into one?
Use interactive rebase (git rebase -i) to squash multiple commits into one by changing "pick" to "squash" for the commits to be squashed.
Q.55 What is "Git blame," and how is it used?
Git blame shows the commit and author responsible for each line in a file, helping identify the origin of specific changes.
Q.56 How do you compare differences between branches in Git?
Use the git diff command followed by the branch names or commits to see the differences between branches.
Q.57 How do you rename a Git branch?
Use the git branch -m command followed by the old branch name and the new branch name to rename a branch.
Q.58 What is "Git submodules," and why are they used?
Git submodules allow you to include other Git repositories as subdirectories in your project, maintaining separate version control.
Get Govt. Certified Take Test