Git Questions

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

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.