50 git Questions- Must to know

Here are 50 git questions ranging from basic to advanced, along with their answers:

IN TODAY'S EDIT

Interview Q&A

50 git Questions- Must to know

🚀 Top News

Siri's Silent Listen: Apple's $95 million privacy settlement and what it means for you

📚️ Resources :

Learn New Thing: Tutorial for Selenium automation testing tool lovers.

Want to prepare for Interviews & Certifications

Interview Q&A:

Basic Git Interview Questions

What is Git?

Git is a distributed version control system that tracks changes in source code during software development.

What are the key features of Git?

Key features include distributed development, version tracking, branching, merging, and lightweight operations.

How is Git different from other VCS like SVN?

Git is distributed, while SVN is centralized. Git allows offline work and provides better branching/merging capabilities.

What is a repository in Git?

A repository is a storage space where Git tracks all versions of files and directories.

What are the types of Git repositories?

Local and remote repositories.

How do you initialize a Git repository?

git init

How to clone an existing repository?

git clone

What is the difference between Git pull and Git fetch?

git pull fetches and merges changes, while git fetch only retrieves the latest changes.

How do you check the current Git status?

git status

What is the purpose of the .gitignore file?

It is used to specify files and directories that should be ignored by Git.

How to add changes to the staging area?

git add

How to commit changes in Git?

git commit -m "Commit message"

What is a branch in Git?

A branch is an independent line of development in a project.

How do you create a new branch?

git branch

How to switch to a different branch?

git checkout

What command merges two branches?

git merge

How do you delete a branch locally?

git branch -d

How do you delete a remote branch?

git push origin --delete

What is the difference between merge and rebase?

merge creates a new commit, while rebase integrates changes without an additional commit.

How to see the commit history?

git log

What is the difference between git reset and git revert?

git reset moves HEAD back to a previous state, whereas git revert creates a new commit to undo changes.

How to revert a specific commit?

git revert

How to discard changes in a file before committing?

git checkout --

How to remove a file from Git tracking but keep it locally?

git rm --cached

How to stash changes in Git?

git stash

How to apply stashed changes?

git stash apply

How to view remote repositories?

git remote -v

How to push changes to a remote repository?

git push origin

What is a detached HEAD in Git?

It means you are not on a branch but pointing directly to a commit.

How to rename a branch?

git branch -m old_name new_name

Advanced Git Interview Questions

What is the difference between soft, mixed, and hard reset?

--soft: Moves HEAD but keeps changes staged.

--mixed: Moves HEAD and unstages changes.

--hard: Moves HEAD and discards changes.

What are Git submodules?

Submodules allow including another Git repository inside a repository.

How to update a submodule?

git submodule update --remote

How does Git handle merge conflicts?

Git marks conflicting files and requires manual resolution before committing.

What is the use of git cherry-pick?

It applies a specific commit from one branch to another.

How to rebase interactively?

git rebase -i HEAD~3

What is Git bisect?

It is used to find the commit that introduced a bug by binary search.

What is Git reflog?

It tracks changes to HEAD and allows recovering lost commits.

How to remove the last commit without losing changes?

git reset --soft HEAD~1

How do you create an annotated tag?

git tag -a v1.0 -m "Version 1.0"

What is the difference between annotated and lightweight tags?

Annotated tags store metadata, while lightweight tags are just pointers.

How do you force push changes?

git push --force

What is the significance of git config?

It allows setting up user-specific configuration settings.

What is the purpose of the git fsck command?

It checks for integrity issues in the Git repository.

How to squash commits in Git?

git rebase -i HEAD~n

What is the difference between git archive and git bundle?

git archive creates a ZIP/tarball, while git bundle stores the entire repo history.

How to find a specific commit in the history?

git log --grep="commit message"

What is the difference between git stash pop and git stash apply?

pop applies and removes the stash, while apply keeps it.

How to set up tracking for a new remote branch?

git branch --set-upstream-to=origin/

How can you undo a merge?

git reset --hard ORIG_HEAD

Reply

or to participate.