Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Git Interview Questions and Answer Part – 10

Where can HEAD point?

  • To a branch
  • To a branch or nowhere
  • To a branch or a commit (Ans)
  • To a branch, a commit, a tree, or a blob

How does “git rebase” move an existing commit?

  • It copies over the commit to a new commit with a different parent and SHA1. (Ans)
  • None of these
  • It just changes the parent in the commit file.
  • It changes the commit’s parent and its SHA1.

What’s one difference between merges and rebases?

  • Rebases change history, merges don’t. (Ans)
  • None of these
  • Rebases create commits with multiple parents, merges don’t.
  • Merges create a new commit object, rebases don’t

What’s a “pull”?

  • A “merge” followed by a “push”
  • A “push” followed by a “merge”
  • A “fetch” followed by a “push”
  • A “fetch” followed by a “merge” (Ans)

Which of these is not a Git command?

  • git fetch
  • git fork (Ans)
  • git push
  • git clone

The setting, core.autocrlf, configures:

  • automatic addition of line breaks to commit messages.
  • autocorrection of spelling errors in commit messages.
  • conversion of line endings between the repository and working copy. (Ans)
  • stripping extra line breaks from the end of files.

Which command creates a local git repository?

  • git localrepo
  • git init (Ans)
  • git repo
  • git initrepo

Performing a git pull is equivalent to a git fetch followed by:

  • git merge (Ans)
  • git rebase
  • git cherry-pick
  • git reset –hard

Cherry-picking a commit will:

  • apply only that commit to the current branch. (Ans)
  • remove the commit from its source branch and apply it to the current branch.
  • apply that commit and all subsequent commit to the current branch.
  • apply that commit and all previous commits to the current branch.

The advantage of a DVCs is:

  • full local history
  • easy backups
  • all of these (Ans)
  • reliable branching/merging
  • different topologies

To remove and discard the changes from the last commit on your current branch, you should use:

  • git reset –soft HEAD
  • git revert HEAD
  • git revert HEAD~1
  • git reset –hard HEAD
  • git reset –hard HEAD~1 (Ans)

Which URL style should you use if you want to avoid using passwords?

  • http://github.com/username/repository.git
  • git@github.com:username/repository.git (Ans)
  • git://github.com/username/repository.git
  • https://github.com/username/repository.git

Given an unmerged feature branch, feature1, what is the effect of running “git branch -d feature1”?

  • Deletion of feature1 will fail silently
  • feature1 will not be deleted and an error message will be displayed (Ans)
  • Git will display the prompt “Unmerged changes. Confirm delete? (y/N)”
  • feature1 will be deleted

User-level configuration in Git can be modified using:

  • git config –system
  • git config
  • git config –user
  • git config –global (Ans)

Which file lists the files and directories that should not be committed to the repository?

  • .git/config
  • .gitnocommit
  • .gitattributes
  • .gitignore (Ans)

What feature in Git allows you to become more efficient at the command line?

  • Speech recognition
  • Keyboard shortcuts
  • Snippets
  • Aliases (Ans)

When is a commit A said to be reachable from another commit B?

  • When B is an ancestor of A
  • When A is the direct parent of B
  • When A and B are patch equivalent
  • When A is an ancestor of B (Ans)

How can Git calculate patches on the fly?

  • It’s really good at math.
  • It uses the patience algorithm.
  • It stores the entire files in the working directory for each commit. (Ans)
  • It stores deltas between files in the working directory.

What is the difference between the -S and -G options of git log?

  • -S searches for matching lines that are removed, while -G searches for lines that are added.
  • -S searches for matching lines that are either added, removed, or modified, while -G only includes lines that are modified.
  • -S searches for matching lines that are either added or removed, while -G also includes lines that are modifie- (Ans)
  • -S searches for matching lines that are either added or removed, while -G also includes lines that are modified.

In which scenario is git rerere useful?

  • When dealing with complex merge conflicts
  • When merging more than two branches
  • When dealing with a lot of different merge conflicts
  • When dealing with the same merge conflict more than once (Ans)
Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)