A beginner-friendly and experienced-developer-ready Git guide covering daily workflow, branches, merging, rebasing, recovery, collaboration, and practice questions.
Published: Sep 2019 Updated: May 2026
git status often and review diffs before committing.| Part | Meaning | Command to inspect |
|---|---|---|
| Working tree | Files you are editing now. | git status |
| Staging area / index | Changes selected for the next commit. | git diff --staged |
| Commit | A snapshot with message, author, date, and parent links. | git show |
| Branch | A movable pointer to a commit. | git branch |
| HEAD | Your current branch or checked-out commit. | git status |
| Remote | Another repository such as origin. | git remote -v |
git switch main then git pull --ff-only.git switch -c feature/login.git status and git diff.git add file.git diff --staged.git commit -m "Add login form validation".git push -u origin feature/login.| Goal | Command | Point |
|---|---|---|
| Start repository | git init | Create local Git history. |
| Clone repository | git clone <url> | Copy remote repository locally. |
| Check state | git status | Shows branch, staged, unstaged, untracked files. |
| Stage changes | git add | Move selected changes into the index. |
| Commit | git commit | Create a snapshot. |
| Fetch | git fetch | Download remote refs without merging. |
| Pull | git pull | Fetch plus merge or rebase. |
| Push | git push | Upload commits to remote. |
feature/payment-filter or fix/login-error.| Action | What it does | Use when |
|---|---|---|
| Merge | Combines histories and may create a merge commit. | You want to preserve branch history. |
| Rebase | Replays commits on a new base. | You want to clean private feature branch history. |
| Squash merge | Combines feature branch into one target-branch commit. | Feature commits are noisy and main should stay concise. |
| Need | Command | Safe use |
|---|---|---|
| Unstage file | git restore --staged file | Removes file from staging only. |
| Discard local edits | git restore file | Deletes unstaged edits intentionally. |
| Undo pushed commit | git revert <commit> | Creates a new inverse commit. |
| Recover lost pointer | git reflog | Finds previous HEAD/branch positions. |
| Temporarily save work | git stash push -m "message" | Shelves uncommitted changes. |
git status to find conflicted files.git add.git bisect: binary search to find the commit that introduced a bug.git worktree: check out multiple branches without cloning again.git cherry-pick: apply one selected commit to the current branch.git tag -a: mark releases with metadata.git range-diff: compare two versions of a patch series after rebase.git sparse-checkout: work with only part of a large repository.git status show?git revert.git reset --soft do?git restore do?git stash?git reflog?git diff and git diff --staged.Explore 500+ free tutorials across 20+ languages and frameworks.