Git Questions

Warm up for Git questions with most asked questions and answers for junior, mid, and senior roles.

Junior

How can you initialize a repository in Git?

Show Answer

To initialize a repository in Git, you can use the git init command.

Junior

What is Git?

Show 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.

Junior

What’s the difference between Git and GitHub?

Show 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.

Junior

Which command is used to create an empty Git repository?

Show Answer
git init
Junior

What do you understand about the Git merge conflict?

Show Answer

A merge conflict happens when Git is unable to automatically resolve differences in code between two commits.

Mid

Name a few Git commands with their function.

Show Answer

The following are the most common Git commands:

  • git add - adds files to the staging area
  • git commit - commits the current changes
  • git push - pushes the current branch to a remote repository
  • git pull - pulls changes from a remote repository
  • git status - shows the status of the current repository
  • git log - shows the history of the current repository
Mid

What does git pull origin master do?

Show 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.

Mid

What does the git push command do?

Show Answer

The "git push" command is used to push changes to a remote repository. It pushes the current branch to a remote repository.

Mid

What does git clone do?

Show Answer

The git clone command is used to clone a repository from a remote repository.

Mid

What is Git stash?

Show 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.

Mid

What is the functionality of git clean command?

Show Answer

The git clean command is used to remove untracked files from the working directory.

Mid

What is the difference between fork, branch, and clone?

Show 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.

Mid

What is git stash drop?

Show Answer

Git stash drop is a command that removes a stash from the stash list.

Mid

What is “git cherry-pick”?

Show Answer

Git cherry-pick is a command that allows you to cherry-pick a commit to a branch.

Mid

What are the advantages of using Git?

Show Answer

Some of the advantages of Git are:

  • Speed
  • Simplicity
  • Fully Distributed
  • Excellent support for parallel development, support for hundreds of parallel branches.
  • Integrity
Mid

What language is used in Git?

Show 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.

Mid

What is the correct syntax to add a message to a commit?

Show Answer

The correct syntax is:

git commit -m “message”
Mid

What does git status command do?

Show Answer

Git status command is used to show the status of the current repository.

Mid

What is the HEAD term in Git?

Show Answer

The HEAD in Git is the pointer to the current branch reference.

Mid

What does git diff command do?

Show Answer

Git diff command is used to show the difference between two commits.

Senior

How is git merge different from git rebase?

Show 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.

Senior

What consists of a commit object?

Show Answer

The commit object contains the directory tree object hash, parent commit hash, author, committer, date and message.

Senior

Can you tell something about git reflog?

Show Answer

Git reflog is a command that shows a more detailed history of a branch.

Senior

What do you understand about the Staging area in Git?

Show 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.

Senior

What is Git Bisect and how do you use it?

Show Answer

Git bisect is a tool that allows you to find the commit that introduced a bug in your code.

Senior

Difference between git fetch and git pull.

Show 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

Senior

What is the functionality of git ls-tree?

Show Answer

The git ls-tree command is used to list the contents of a tree object.

Senior

What is the difference between git revert and git reset?

Show 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.

Senior

What is SubGit and why is it used?

Show Answer

SubGit is a Git submodule. It is a way to add a repository as a submodule to another repository.