Ultimate Git Commands Guide
Master Git from beginner to advanced with commands, interview questions and interactive Git playground.
What is Git?
Git is a distributed version control system used for tracking code changes, collaboration and DevOps workflows.
Git Commands with Description
git init
Creates a new Git repository inside current project folder.
git init
git clone
Downloads an existing remote repository into your local machine.
git clone https://github.com/user/repo.git
git status
Shows modified, staged and untracked files in repository.
git status
git add .
Adds all changed files into staging area before commit.
git add .
git commit -m
Creates snapshot of staged changes with commit message.
git commit -m "Added login automation"
git push
Uploads local commits to remote repository server.
git push origin main
git pull
Downloads latest changes and merges them into local branch.
git pull
git fetch
Downloads repository updates without merging changes.
git fetch
git branch
Displays available branches in repository.
git branch
git checkout -b
Creates and switches to a new branch.
git checkout -b feature-login
git merge
Combines one branch into another branch.
git merge feature-login
git stash
Temporarily saves unfinished changes without commit.
git stash
git rebase
Moves branch commits onto another base branch.
git rebase main
git cherry-pick
Copies selected commit from one branch into another branch.
git cherry-pick a1b2c3
git reset --hard
Deletes commits and removes changes permanently.
git reset --hard HEAD~1
git log
Displays repository commit history.
git log
Most Used Git Commands Table
| Command | Description |
|---|---|
| git init | Initialize repository |
| git clone | Clone repository |
| git add . | Add all files |
| git commit | Create commit |
| git push | Upload changes |
| git pull | Download latest changes |
| git stash | Temporary save changes |
| git rebase | Reapply commits |
| git cherry-pick | Copy commit |
Git Interview Questions & Answers
1. What is Git?
Git is a distributed version control system used for tracking and managing source code changes.
2. Difference between Git and GitHub?
Git is a version control software while GitHub is a hosting platform for Git repositories.
3. What is staging area?
Staging area is an intermediate area where changes are prepared before commit.
4. What is branching in Git?
Branching allows developers to work independently on features without affecting main branch.
5. What is merge conflict?
Merge conflict occurs when multiple branches modify same lines differently.
6. Difference between pull and fetch?
Fetch downloads changes only while pull downloads and merges automatically.
7. What is Git stash?
Git stash temporarily stores unfinished changes without committing them.
8. What is HEAD in Git?
HEAD points to latest commit in current branch.
9. What is Git rebase?
Git rebase reapplies commits on another branch to maintain clean history.
10. Difference between reset and revert?
Reset removes commits while revert safely creates reverse commit.
11. What is cherry-pick?
Cherry-pick copies a selected commit into another branch.
12. What is .gitignore?
.gitignore excludes unnecessary files from Git tracking.
13. What is detached HEAD state?
Detached HEAD means Git points directly to commit instead of branch.
14. What is upstream branch?
Upstream branch is linked remote tracking branch for local branch.
15. Explain Git workflow.
Modify files → Add changes → Commit changes → Push to remote repository.
Interactive Git Playground
Practice Git commands directly inside browser.
Comments
Post a Comment