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:

  1. Working Directory

  2. Staging Area

  3. 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 stash
git 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:

  1. Identify conflicting files

  2. Edit manually

  3. Remove conflict markers

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

Popular posts from this blog

Database Integration in FastAPI (SQLAlchemy CRUD)

Middleware & CORS in FastAPI

Python Data Handling