Git Questions & Answers
1️⃣ What is Git?
Git is a distributed version control system that tracks changes in source code and enables collaborative development.
Unlike centralized systems, Git stores full repository history locally.
2️⃣ What is the difference between Git and GitHub?
-
Git → Version control tool
-
GitHub → Cloud platform to host Git repositories
Other alternatives:
-
GitLab
-
Bitbucket
3️⃣ Explain Git Architecture
Git has three main areas:
-
Working Directory
-
Staging Area
-
Repository (.git folder)
Flow:
Working Directory → Staging Area → Local Repository → Remote Repository
4️⃣ What is the difference between merge and rebase?
🔹 Merge
-
Combines branches
-
Keeps history intact
-
Creates merge commit
git merge feature-branch
🔹 Rebase
-
Rewrites commit history
-
Creates linear history
-
Cleaner commit log
git rebase main
Best Practice:Use rebase for local cleanup, merge for shared branches.
5️⃣ What is Git Stash?
Temporarily saves uncommitted changes.
git stashgit stash pop
Useful when switching branches quickly.
6️⃣ What is Cherry-Pick?
Apply a specific commit from another branch.
git cherry-pick <commit_id>
Used in hotfix scenarios.
7️⃣ How to Resolve Merge Conflicts?
Steps:
-
Identify conflicting files
-
Edit manually
-
Remove conflict markers
-
Add and commit
8️⃣ What is HEAD in Git?
HEAD is a pointer to the current active branch.
9️⃣ What is the difference between reset and revert?
| Command | What it Does |
|---|---|
reset | Moves HEAD and rewrites history |
revert | Creates new commit to undo changes |
Use revert in shared branches.
🔟 What is Git Reflog?
Tracks all movements of HEAD.Useful for recovering deleted commits.
git reflog
Comments
Post a Comment