git statusDisplays the state of modified, tracked, and untracked files
Run this before staging files to verify exactly what changed.
Git is not a black box: your files move across 4 key stages. Click any pipeline arrow or module below to explore exact commands and how to master them.

Move changes from the working directory to the Staging Area (Index).
git statusDisplays the state of modified, tracked, and untracked files
Run this before staging files to verify exactly what changed.
git diffShows unstaged line-by-line code differences
Compares your working directory against the staging area.
git add Stages a specific file for the next commit
Example: git add index.html styles.css
git add .Stages all changes in the current directory and subdirectories
Includes modifications, new files, and deletions.
git add -pInteractive patch mode: review and stage hunk by hunk
Best practice for crafting clean, atomic commits.
Capture a permanent snapshot from staging area into the local repository.
git commit -m "feat: clear message"Creates a new commit with a descriptive message
Follow conventions like Conventional Commits (feat, fix, docs, refactor).
git commit -am "message"Stages tracked files and commits in a single command
Does not include untracked new files created recently.
git commit --amendModifies the most recent commit (add changes or update message)
Use only before pushing your commit to a shared remote repository.
git log --oneline --graph --decorateVisualizes commit history in a concise ASCII tree graph
Essential command to inspect branch divergence and HEAD location.
Upload your local commits to the shared remote repository.
git push origin Pushes local commits to the specified remote branch
Example: git push origin feat/login
git push -u origin Pushes and sets up upstream tracking for future shortcut pushes
After this, you can just run `git push` or `git pull` on this branch.
git push --force-with-leaseSafe force-push: overwrites remote only if no one else pushed new work
Always prefer this over destructive `git push --force`.
git push origin --delete Deletes a feature branch from the remote server after merging
Keeps the remote repository tidy and free of dead branches.
Retrieve changes from the remote server into your local environment.
git fetch originDownloads latest remote references without touching working files
Safe and non-destructive: updates origin/main without merge conflicts.
git pull origin Fetches remote changes and merges them immediately into current branch
Shorthand equivalent to: git fetch + git merge.
git pull --rebase origin Pulls remote changes and replays your local commits on top cleanly
Avoids cluttering the commit graph with unnecessary merge commits.
Revert uncommitted modifications or move between commit snapshots.
git restore Discards uncommitted changes in working directory for a file
Irreversible action! Restores the file to the last committed state.
git restore --staged Unstages a file back into working directory without losing edits
The modern and clear replacement for the confusing `git reset HEAD <file>`.
git clean -fdRemoves untracked files and directories from your working tree
Always run `git clean -nd` first to dry-run and preview what will be erased.
Global Git configuration, identity, default branch, and aliases.
git config --global user.name "Your Name"Sets the author name associated with all your future commits
Configures your identity in ~/.gitconfig.
git config --global user.email "you@example.com"Sets the author email associated with your commits
Must match your GitHub/GitLab verified account email.
git config --global init.defaultBranch mainSets "main" as default branch name for all new repositories
Industry standard replacing legacy master naming.
git config --list --show-originDisplays all active Git configurations and where each file is located
Great for debugging SSH, credential helper, or user identity conflicts.
Create, navigate, rename, and manage isolated lines of development.
git branchLists all local branches and highlights active branch with asterisk
Use `git branch -a` to view remote tracking branches as well.
git switch Switches to an existing branch (modern recommended syntax)
Modern, unambiguous alternative to legacy `git checkout <branch>`.
git switch -c Creates a new branch and immediately switches into it
Example: git switch -c feat/user-authentication
git branch -d Safely deletes a local branch that has already been merged
Use -D with caution to force deletion of unmerged branches.
git branch -m Renames the currently checked out branch
Quickly fixes typos in branch names.
Integrate feature branches, resolve conflicts, and maintain clean linear history.
git merge Merges the specified branch into your current active branch
Creates a merge commit unless fast-forward is possible.
git merge --no-ff Forces creation of a merge commit even if fast-forward is possible
Preserves the historical boundary of a feature branch.
git rebase Replays current branch commits on top of base-branch tip
Creates a pristine linear history without merge bubbles.
git rebase -i HEAD~3Interactive rebase: squash, edit, reorder, or drop last 3 commits
Clean up local WIP commits before opening a pull request.
git merge --abortAborts an active merge process and resets files to pre-merge state
Your emergency escape button when merge conflicts get messy.
Temporarily shelve uncommitted work to switch context without committing.
git stashSaves uncommitted modifications into a temporary stash stack
Leaves working directory completely clean to switch branches.
git stash save "wip: working on checkout form"Saves changes with a clear descriptive message for later retrieval
Helpful when you have multiple stashes saved.
git stash popReapplies the most recent stashed changes and drops it from the stack
Restores your shelved changes right where you left off.
git stash listLists all currently saved stash entries in the repository
Displays stash@{0}, stash@{1}, etc.
git stash clearDeletes all stored stashes permanently
Use with caution: dropped stashes cannot be restored easily.
Recover discarded commits, unstage files, and travel back in time.
git reflogChronological safety diary of every HEAD movement in your repository
Your #1 tool to recover accidentally deleted branches or reset commits.
git reset --soft HEAD~1Undoes last commit while keeping its changes staged in Index
Perfect for modifying a commit message or adding forgotten files.
git reset --hard HEAD~1Destroys last commit and wipes out its working directory changes
Dangerous! Only use if you are 100% sure you want to discard the work.
git revert Creates a new commit that records the exact inverse of a past commit
The safe and standard way to undo bugs already pushed to production.
Matches found across all command categories.
Experience the Git lifecycle in real time. Run sample commands to watch terminal outputs and follow how changes progress through pipeline stages.
On branch main Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: src/app.js modified: public/styles.css Untracked files: (use "git add <file>..." to include in what will be committed) src/auth.js no changes added to commit (use "git add" to track)
Observe how commits connect and reorder in real time when running merge or rebase operations in Git.
Learn what actually happens when Git pauses during a merge or rebase. Practice resolving real code collisions and understand the <<<<<<< HEAD markers.
Merge conflict while updating authentication method and JWT token expiration window.
git add src/config/auth.tsgit merge --continuegit merge --abortFind which exact commit introduced a bug in production using binary search O(log N). Step through bisecting good/bad revisions or automate with tests.
Commit C8 is broken (bad) and C1 is verified working (good). Click Start to let Git bisect the midpoint.
a1b2c3dfeat: setup base project structuree4f5a6bfeat: add user login endpointc7d8e9ffix: handle token expiration1a2b3c4perf: optimize sql queries in auth5e6f7a8refactor: change payload signature in parser9b0c1d2style: format response json outputs3e4f5a6docs: update api swagger documentation7b8c9d0feat: add analytics event pingExperiment visually with interactive rebase. Reorder commits, squash bugfixes, reword messages, or drop commits without fear. Discover why Git recalculates SHA-1 hashes and creates a pristine linear history.
# git-rebase-todo previewGit mistakes happen to everyone. Find your exact scenario and follow verified steps to recover your code without panicking.
Move your latest commit to a new feature branch safely
You made code changes and committed directly to the main branch instead of creating an isolated feature branch.
git branch feat/my-correct-branchCreates the new feature branch pointer right at the current commit.
git reset --hard HEAD~1Rewinds main branch back by 1 commit, leaving main pristine.
git switch feat/my-correct-branchSwitches into your new branch where your commit is waiting untouched.
If you already pushed the commit to GitHub, avoid reset --hard; use `git revert` to create an audit-safe inverse commit.
Fix the most recent commit instantly
You made a typo in the commit message or realized you forgot to stage one more file.
git add forgotten-file.js(Optional) If you missed a file, stage it first with git add.
git commit --amend -m "feat: corrected descriptive message"Overwrites the message and absorbs staged files into the previous commit.
Only use --amend before pushing your commit to a remote shared repository.
Remove sensitive files before deploying to production
You staged and committed private credentials or secrets into your local Git repository.
echo ".env" >> .gitignoreEnsures Git ignores future edits to the secret configuration file.
git rm --cached .envRemoves .env from Git tracking without deleting it from your local disk.
git commit -m "chore: remove sensitive env credentials from tracking"Records the removal in history.
If you already pushed secrets to GitHub, immediately rotate and revoke the compromised API keys in your provider dashboard.
Abort the merge and return to a clean working state
You ran git merge, encountered dozens of conflict markers (<<<<<<<), and want to start over.
git merge --abortCancels the merge in progress and cleanly restores all files.
If resolving an interactive rebase conflict, the equivalent command is `git rebase --abort`.
Time travel rescue using the Git Reflog diary
You deleted a branch thinking it was merged, or ran git reset --hard by mistake.
git reflogDisplays a chronological ledger of every time HEAD moved in your repository.
git switch -c recovered-branch HEAD@{2}Creates a new branch pointing directly to the commit before the accidental deletion.
Git Reflog keeps orphaned commits for roughly 30 to 90 days before running garbage collection.
Learn industry-standard procedures. Every step includes the exact terminal command and the mental model reasoning behind it.
Learn the exact initial sequence to turn a local directory into a cloud-hosted Git repo.
Creates the hidden .git directory to begin version control.
git initPrepares your code in the Staging Area.
git add .Creates your initial permanent snapshot.
git commit -m "feat: initial project setup"Connects your local project with GitHub/GitLab origin URL.
git remote add origin https://github.com/user/my-repo.gitUploads your main branch and sets upstream tracking.
git push -u origin mainThe global industry standard for developers working in parallel.
Pull latest approved changes from teammates before branching.
git switch main && git pullOpen an isolated branch lane with a descriptive semantic name.
git switch -c feat/oauth-authenticationRecord small, atomic units of work.
git add . && git commit -m "feat(auth): add google sign-in"Upload branch to GitHub to request team peer review.
git push -u origin feat/oauth-authenticationMaster how to identify, resolve, and commit when two people edit the same lines.
Git flags files with overlapping changes.
git statusOpen file and look for <<<<<<< HEAD and >>>>>>> branch.
code <conflicted-file>Tells Git you resolved the differences.
git add <resolved-file>Completes the merge process cleanly.
git commit -m "merge: resolve conflicts with main"Clear up common Git confusion. Understand key technical differences, pros/cons, and the exact moment to use each option.
git fetchDownloads latest commits, refs, and branches from the remote server WITHOUT altering your working directory files.
When you want to see what your teammates pushed without risking merge conflicts in your active files.
git pullExecutes git fetch and immediately merges remote changes into your current active local branch.
When you want to update your local branch quickly and you know your working tree is clean.
git mergeCombines two independent branch histories by creating an explicit join commit with two parent commits.
When closing a feature branch via Pull Request to preserve historical context of branch lifetime.
git rebaseTakes your feature commits and replays them one by one on top of the newest commit of the base branch.
To clean up local commits before opening a Pull Request and keep history completely linear.
git restore & resetAffects the local working tree and index. Restore discards uncommitted file edits; reset moves branch pointers.
To undo uncommitted mistakes or rearrange local unpushed commits.
git revertCreates a brand NEW commit that applies the mathematically exact inverse of the commit you wish to cancel.
Whenever a bug has already been pushed to main, GitHub, or production.
git switchModern command (Git 2.23+) designed with a single responsibility: navigate or create branches.
Whenever you change branches or create a new branch using the -c flag.
git checkoutLegacy multi-tool command that handled branch navigation and file discarding at the same time.
Only in legacy tutorials or older systems with outdated Git binaries.
Fill in your parameters and get exact commands ready to paste into your terminal, following production-grade best practices.
Create clean branches following conventional naming standards.
git switch -c feat/oauth-authenticationGenerates the complete set of commands to publish a local project directly to GitHub in one run.
Learn to write clean, standardized messages following the Conventional Commits specification. Improves git log clarity and enables automated semantic releases and changelogs.
git commit -m "feat(auth): implement jwt token authentication"Prevent accidental leakage of secrets, API keys, or bulky folders like node_modules/. Select your stack and download a ready-to-use file.
Senior developers do not retype repetitive commands. Configure high-speed aliases and battle-tested global flags directly in your ~/.gitconfig.
Visual, ultra-compact colored history graph formatted into one line per commit.
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relativeShort status display showing current branch and tracking relation to upstream.
git status -sbUnstages changes from the index without discarding local working tree edits.
git restore --stagedUndoes the most recent commit while keeping all changes staged in the index.
git reset --soft HEAD~1Stages modifications into the previous commit without opening the message editor.
git commit --amend --no-editLists local branches with their latest commit SHA, message, and remote tracking status.
git branch -vvSafely deletes all local branches that have already been merged into the active branch.
git !git branch --merged | grep -v "\*" | xargs -n 1 git branch -dQuickly creates a temporary snapshot commit for uncommitted work in progress.
git !git add -A && git commit -m "chore: work in progress [skip ci]"Optimized template including automatic branch rebasing, branch defaults, and reuse of recorded conflict resolutions (rerere).
[init]
defaultBranch = main
[pull]
rebase = true
[rerere]
enabled = true
[core]
autocrlf = input
[color]
ui = auto
[help]
autocorrect = 1
[alias]
st = status -sb
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
undo = reset --soft HEAD~1
unstage = restore --staged
amend = commit --amend --no-edit
br = branch -vv
cleanup = !git branch --merged | grep -v "\\*" | xargs -n 1 git branch -d
wip = !git add -A && git commit -m "chore: work in progress [skip ci]"Prevent bugs, unformatted code, and leaked .env secrets before they ever touch your repository. Copy production-tested hook scripts.
Runs before the commit message editor opens. If it exits with a non-zero code, the commit is aborted immediately.
#!/bin/sh
# 1. Prevent accidental .env secrets commit
if git diff --cached --name-only | grep -E "(^|/).env"; then
echo "ERROR: Attempted commit of sensitive .env file detected!"
echo "Unstage it using: git reset HEAD .env*"
exit 1
fi
# 2. Run linter on staged files
echo "Running code quality checks..."
npm run lint-staged || exit 1Receives the path to the temporary commit message file. Validates that it matches feat:, fix:, docs:, chore:, etc.
#!/bin/sh
MSG_FILE=$1
COMMIT_MSG=$(cat "$MSG_FILE")
# Validate format: type(scope)?: description
REGEX="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9_-]+\))?: .+"
if ! echo "$COMMIT_MSG" | grep -qE "$REGEX"; then
echo "ERROR: Invalid commit message format!"
echo "Required format: feat(auth): imperative summary"
exit 1
fiRuns immediately before transmitting data to the remote origin server during git push. Prevents broken commits from reaching CI/CD.
#!/bin/sh
echo "Running automated test suite before pushing..."
npm test -- --bail
if [ $? -ne 0 ]; then
echo "ERROR: Tests failed. The push was aborted to protect the remote branch."
exit 1
fiRather than manually managing local .git/hooks (which are not tracked by Git), modern web teams use Husky to commit hook configurations directly to the repository.
# 1. Instalar Husky en tu proyecto moderno
npx husky init
# 2. Agregar hook de pre-commit para linter y secretos
echo "npx lint-staged" > .husky/pre-commit
# 3. Agregar hook para validar Conventional Commits
echo "npx --no -- commitlint --edit $1" > .husky/commit-msgGit is not magic—it is a simple cryptographic content-addressable directed acyclic graph (DAG). Discover how Blobs, Trees, Commits, and References work under the surface.
A Blob stores only raw compressed bytes of a file using zlib. It does not store file names, permissions, or timestamps—only raw payload addressed by its cryptographic SHA-1 hash.
git cat-file -p 70a34b270a34b220377e8a93da26042e9154a43c7b3992dconsole.log("Hello World!");
export const API_KEY = "secure_token";Git has its own jargon. Here are technical definitions translated into everyday real-world metaphors so you never forget what each concept represents.
A symbolic pointer referencing the most recent commit on the currently active branch in your repository.
git show HEADA state where HEAD points directly to a specific commit hash rather than a named branch. Any new commits will be lost if you switch away without creating a branch.
git switch -c rescue-changes"origin" is the default alias assigned to the remote repository you cloned. "upstream" is typically the alias for the main source repo when collaborating on open-source.
git remote -vA unique 40-character alphanumeric checksum calculated from the file tree snapshot, author, date, and parent commit.
git log --onelineThe actual unpacked files and directories in your local filesystem that you are editing right now.
git statusAn intermediate preparation layer where changes are formatted and curated before forming the next commit.
git add <file>A merge where the target branch has no diverging commits, allowing Git to move the branch pointer forward without generating a merge commit.
git merge --ff-onlyA command that copies and reapplies the exact patch introduced by a specific commit from any branch into your current branch.
git cherry-pick <commit-hash>The process of combining multiple small or WIP commits into a single cohesive commit before merging into main.
git merge --squash <branch>A local safety journal that records every time HEAD changed position, enabling recovery of deleted branches and lost commits.
git reflogTest your intuition about Git workflows with these practical scenarios.
You edited "styles.css" and ran "git add styles.css", but realized you are not ready to commit it yet.
You want to create a branch named "feat/profile" and switch to it immediately in a single step using modern Git syntax.
You are working on a feature and your manager asks you to urgently review a hotfix on main. You have unfinished code and do not want to create an ugly WIP commit.
A commit introduced a critical production bug and is already merged into the public "main" branch on GitHub.
You just ran "git commit -m 'fix: responsive header'" and immediately realized you forgot to stage "header.css".