Git Questions
Warm up for Git questions with most asked questions and answers for junior, mid, and senior roles.
How can you initialize a repository in Git?
Show AnswerHide Answer
To initialize a repository in Git, you can use the git init
command.
What is Git?
Show AnswerHide Answer
Git is a version control system for tracking changes in computer files and coordinating work on those files. Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
What’s the difference between Git and GitHub?
Show AnswerHide Answer
Git is a version control system for tracking changes in files
GitHub is a cloud-based hosting service that lets you manage Git repositories.
Which command is used to create an empty Git repository?
Show AnswerHide Answer
git init
What do you understand about the Git merge conflict?
Show AnswerHide Answer
A merge conflict happens when Git is unable to automatically resolve differences in code between two commits.
Name a few Git commands with their function.
Show AnswerHide Answer
The following are the most common Git commands:
git add
- adds files to the staging areagit commit
- commits the current changesgit push
- pushes the current branch to a remote repositorygit pull
- pulls changes from a remote repositorygit status
- shows the status of the current repositorygit log
- shows the history of the current repository
What does git pull origin master do?
Show AnswerHide Answer
"git pull origin master" is used to pull changes from a remote repository. It pulls the latest changes from the master branch of the remote repository and merges them into the current branch.
What does the git push command do?
Show AnswerHide Answer
The "git push" command is used to push changes to a remote repository. It pushes the current branch to a remote repository.
What does git clone do?
Show AnswerHide Answer
The git clone command is used to clone a repository from a remote repository.
What is Git stash?
Show AnswerHide Answer
Git stash is a way to store and restore changes to a file or a set of files. It is used to store changes that have not yet been committed.
What is the functionality of git clean command?
Show AnswerHide Answer
The git clean command is used to remove untracked files from the working directory.
What is the difference between fork, branch, and clone?
Show AnswerHide Answer
Fork is a way to create a copy of an existing repository. It is used to create a copy of an existing repository.
Branch is a way to create a new branch in an existing repository. It is used to create a new branch in an existing repository.
Clone is a way to clone a repository from a remote repository. It is used to clone a repository from a remote repository.
What is git stash drop?
Show AnswerHide Answer
Git stash drop is a command that removes a stash from the stash list.
What is “git cherry-pick”?
Show AnswerHide Answer
Git cherry-pick is a command that allows you to cherry-pick a commit to a branch.
What are the advantages of using Git?
Show AnswerHide Answer
Some of the advantages of Git are:
- Speed
- Simplicity
- Fully Distributed
- Excellent support for parallel development, support for hundreds of parallel branches.
- Integrity
What language is used in Git?
Show AnswerHide Answer
The Git language is written in C. The C language makes this possible by reducing the overhead of runtimes associated with high-level languages and helping git to perform better.
What is the correct syntax to add a message to a commit?
Show AnswerHide Answer
The correct syntax is:
git commit -m “message”
What does git status command do?
Show AnswerHide Answer
Git status command is used to show the status of the current repository.
What is the HEAD term in Git?
Show AnswerHide Answer
The HEAD in Git is the pointer to the current branch reference.
What does git diff command do?
Show AnswerHide Answer
Git diff command is used to show the difference between two commits.
How is git merge different from git rebase?
Show AnswerHide Answer
Git merge: moves changes from a branch to another and creates a merge commit. History is preserved.
Git rebase: moves changes from a branch to another but alters the history by moving the origin branch's starting point. It does not create a merge commit.
What consists of a commit object?
Show AnswerHide Answer
The commit object contains the directory tree object hash, parent commit hash, author, committer, date and message.
Can you tell something about git reflog?
Show AnswerHide Answer
Git reflog is a command that shows a more detailed history of a branch.
What do you understand about the Staging area in Git?
Show AnswerHide Answer
The staging area is a temporary area where Git stores changes that have not yet been committed. When you commit, Git moves the changes from the staging area to the commit history.
What is Git Bisect and how do you use it?
Show AnswerHide Answer
Git bisect is a tool that allows you to find the commit that introduced a bug in your code.
Difference between git fetch and git pull.
Show AnswerHide Answer
The git fetch command downloads commits, files from a remote repository into your local repo.
The git pull fetches and merges any commits from the remote branch
What is the functionality of git ls-tree?
Show AnswerHide Answer
The git ls-tree command is used to list the contents of a tree object.
What is the difference between git revert and git reset?
Show AnswerHide Answer
The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified.
The git reset command is used when we want to move the repository back to a previous commit , discarding any changes made after that commit.
What is SubGit and why is it used?
Show AnswerHide Answer
SubGit is a Git submodule. It is a way to add a repository as a submodule to another repository.