Sets the author name for all your commits globally. This name identifies you across all repositories on your machine and appears in every commit's metadata.
Sets the email address for all your commits globally. Essential for identifying the committer and appears alongside your name in all commits.
Example: To set your email globally, run:
git config --global user.email "john@example.com"
git config --list
Configuration🟢 Beginner
Displays all Git configuration settings from both global (~/.gitconfig) and repository-specific (.git/config) files. Useful for verifying your setup.
Example: To view all configuration settings, run:
git config --list
git config --local user.name "Your Name"
Configuration🟡 Intermediate
Sets the author name for only the current repository, overriding global settings. Useful when working on different projects with different identities.
Example: To set a local username for this repository only, run:
git config --local user.name "Work Name"
git config core.editor [editor]
Configuration🟡 Intermediate
Sets the default text editor for Git (used when writing commit messages). Examples: vim, nano, code, gedit.
Example: To set VS Code as your editor, run:
git config --global core.editor "code --wait"
git clone [url]
Repository🟢 Beginner
Creates a complete local copy of a remote repository. Downloads all commits, branches, and history from the remote source (GitHub, GitLab, Bitbucket, etc.).
Initializes a new Git repository in the current directory. Creates the necessary .git folder and metadata to start tracking project changes.
Example: To initialize a new repository, run:
git init
git init [directory]
Repository🟢 Beginner
Creates a new Git repository in a specified directory and initializes it with Git's internal structure.
Example: To initialize a repository in a new folder, run:
git init my-project
git status
Staging & Committing🟢 Beginner
Shows the current state of your working directory and staging area. Displays modified, staged, and untracked files with helpful next-step suggestions.
Example: To check your repository status, run:
git status
git status -s
Staging & Committing🟢 Beginner
Short format of git status. Shows file state using abbreviations (M=modified, A=added, D=deleted, etc.) for a compact view.
Example: To see status in short format, run:
git status -s
git status --porcelain
Staging & Committing🟡 Intermediate
Machine-readable status output. Designed for scripts and automation tools that need to parse repository state programmatically.
Example: To get status for scripting, run:
git status --porcelain
git add [file]
Staging & Committing🟢 Beginner
Stages changes to a specific file for the next commit. Tells Git to include this file in your next commit snapshot.
Example: To stage a specific file, run:
git add index.html
git add .
Staging & Committing🟢 Beginner
Stages all modified and new files in the current directory and subdirectories. Quick way to stage everything you've changed.
Example: To stage all changes in the repository, run:
git add .
git add -A
Staging & Committing🟢 Beginner
Stages all changes globally: modified, new, and deleted files across the entire repository. Different from 'git add .' which doesn't include deletions.
Example: To stage everything including deletions, run:
git add -A
git add -p
Staging & Committing🟡 Intermediate
Interactive staging mode - review your changes hunk by hunk and choose which ones to stage. Great for crafting clean commits with only related changes.
Example: To stage interactively by hunks, run:
git add -p
git add -u
Staging & Committing🟡 Intermediate
Stages only modified and deleted files - not new untracked files. Useful when you've changed existing files but added nothing new.
Example: To stage only tracked file changes, run:
git add -u
git commit -m "Commit message"
Staging & Committing🟢 Beginner
Records staged changes to the repository with a descriptive message. The message should summarize what changed and why - keep it clear and concise.
Example: To commit with a message, run:
git commit -m "Fix: Resolve login form validation bug"
git commit -m "Title" -m "Description"
Staging & Committing🟡 Intermediate
Creates a commit with both a title and detailed description. First message is the short title, second provides context and explanation.
Example: To commit with title and description, run:
git commit -m "Add user authentication" -m "Implements JWT-based auth with refresh tokens"
git commit -a
Staging & Committing🟡 Intermediate
Stages and commits all tracked files that have been modified. Skips the staging step for known files (won't include new untracked files).
Example: To commit all tracked changes, run:
git commit -a
git commit --amend
Staging & Committing🟡 Intermediate
Modifies the most recent commit by adding new staged changes or changing the commit message. Opens editor for message editing.
Example: To fix your last commit, run:
git commit --amend
git commit --amend --no-edit
Staging & Committing🟡 Intermediate
Adds staged changes to the last commit without changing its message. Quick way to add forgotten files to previous commit.
Example: To add forgotten files to last commit, run:
git commit --amend --no-edit
git commit --allow-empty -m "message"
Staging & Committing🔴 Advanced
Creates a commit with no changes. Useful for triggering CI/CD pipelines or creating milestone commits with no actual code changes.
Pushes a branch to remote and sets it as the upstream. The -u flag establishes tracking - essential for first push of new branches.
Example: To push and set upstream, run:
git push -u origin feature-login
git push [remote] [branch]
Remote🟢 Beginner
Uploads commits from your local branch to the remote. After initial -u setup, just use this simpler form.
Example: To push commits, run:
git push origin main
git push --all
Remote🟡 Intermediate
Pushes all local branches to the remote at once, rather than pushing them individually.
Example: To push all branches, run:
git push --all
git push --force
Remote🔴 Advanced
Forces a push even if it overwrites remote commits. **Use with extreme caution** - can cause loss for other team members. Only use in private branches.
Example: To force push (use cautiously), run:
git push --force origin feature-branch
git push --force-with-lease
Remote🔴 Advanced
Safer alternative to --force that only overwrites if no one else has pushed. Protects against accidentally losing others' work.
Example: To safely force push, run:
git push --force-with-lease origin feature-branch
git push [remote] --delete [branch]
Remote🟡 Intermediate
Deletes a branch on the remote repository. Useful for cleaning up old feature branches after merging.
Example: To delete a remote branch, run:
git push origin --delete feature-old
git push --tags
Remote🟡 Intermediate
Pushes all local tags to remote without pushing any commits. Useful for publishing release versions.
Example: To push all tags, run:
git push --tags
git pull [remote] [branch]
Remote🟢 Beginner
Fetches and merges changes from a remote branch into your current branch. Combines 'fetch' and 'merge' in one command.
Example: To pull changes, run:
git pull origin main
git pull
Remote🟢 Beginner
Pulls from the tracked upstream branch (usually the branch you've previously pushed). Uses branch tracking to know where to pull from.
Example: To pull from tracked upstream, run:
git pull
git pull --rebase
Remote🟡 Intermediate
Fetches changes and rebases your commits on top instead of merging. Keeps history linear and clean without merge commits.
Example: To pull with rebase, run:
git pull --rebase origin
git fetch [remote]
Remote🟢 Beginner
Downloads new commits and objects from remote without merging. Updates remote-tracking branches but leaves your working directory untouched.
Example: To fetch updates, run:
git fetch origin
git fetch --prune
Remote🟡 Intermediate
Fetches and removes stale remote-tracking branches for branches that no longer exist on remote. Cleans up deleted branches.
Example: To fetch and prune, run:
git fetch --prune
git fetch --all
Remote🟡 Intermediate
Fetches updates from all remote repositories, not just the default 'origin'. Useful when working with multiple remotes.
Example: To fetch from all remotes, run:
git fetch --all
git merge [branch_name]
Merging & Rebasing🟢 Beginner
Combines commits from another branch into your current branch. Creates a merge commit linking the two branches' histories.
Example: To merge a branch, run:
git merge feature-login
git merge --no-ff [branch]
Merging & Rebasing🟡 Intermediate
Merges while creating a merge commit even if fast-forward is possible. Preserves branch structure in history for better traceability.
Example: To merge with history preserved, run:
git merge --no-ff feature-settings
git merge --squash [branch]
Merging & Rebasing🟡 Intermediate
Combines all commits from another branch into a single commit before merging. Cleans up history by consolidating branch work into one commit.
Example: To squash and merge, run:
git merge --squash feature-temp-work
git merge --abort
Merging & Rebasing🟡 Intermediate
Cancels an ongoing merge process if you encounter conflicts or change your mind. Returns to the state before the merge started.
Example: To abort a merge, run:
git merge --abort
git rebase [branch]
Merging & Rebasing🟡 Intermediate
Re-applies your commits on top of another branch. Creates cleaner, linear history compared to merging by replaying commits.
Example: To rebase, run:
git rebase main
git rebase -i [commit]
Merging & Rebasing🔴 Advanced
Interactive rebase - reorder, squash, or edit commits. Powerful tool for cleaning up commit history before pushing.
Example: To rebase interactively, run:
git rebase -i HEAD~3
git rebase --abort
Merging & Rebasing🟡 Intermediate
Cancels an ongoing rebase if you encounter conflicts or issues. Returns to the state before rebase started.
Example: To cancel a rebase, run:
git rebase --abort
git rebase --continue
Merging & Rebasing🟡 Intermediate
Resumes a paused rebase after resolving conflicts. Git continues applying the remaining commits.
Example: To continue after resolving conflicts, run:
git rebase --continue
git cherry-pick [commit]
Merging & Rebasing🟡 Intermediate
Applies changes from a specific commit onto your current branch. Useful for selectively bringing in changes without merging entire branches.
Example: To cherry-pick a commit, run:
git cherry-pick abcd123
git cherry-pick [commit1] [commit2] ...
Merging & Rebasing🟡 Intermediate
Cherry-picks multiple specific commits in sequence. Useful for integrating several commits without merging.
Example: To cherry-pick multiple, run:
git cherry-pick abcd123 efgh456
git cherry-pick --abort
Merging & Rebasing🟡 Intermediate
Cancels an ongoing cherry-pick operation. Returns to the state before cherry-pick started.
Example: To cancel cherry-pick, run:
git cherry-pick --abort
git stash
Stashing🟡 Intermediate
Temporarily saves work-in-progress changes without committing. Cleans your working directory so you can switch branches or pull updates.
Example: To save work temporarily, run:
git stash
git stash save "Work in progress"
Stashing🟡 Intermediate
Stashes changes with a descriptive message for easier identification when reviewing stashes later.
Example: To stash with a message, run:
git stash save "WIP: User auth form"
git stash list
Stashing🟡 Intermediate
Lists all stashed changes with references (stash@{0}, stash@{1}, etc.). Helps you track saved work.
Example: To view all stashes, run:
git stash list
git stash apply
Stashing🟡 Intermediate
Applies a stash back to your working directory without removing it from the stash list. Stash remains available.
Example: To apply a stash, run:
git stash apply stash@{0}
git stash pop
Stashing🟡 Intermediate
Applies the most recent stash and removes it from the stash list. One-command alternative to apply + drop.
Example: To apply and remove most recent stash, run:
git stash pop
git stash drop [stash]
Stashing🟡 Intermediate
Permanently deletes a specific stash. Once dropped, the stashed changes cannot be recovered.
Example: To delete a stash, run:
git stash drop stash@{0}
git stash clear
Stashing🟡 Intermediate
Permanently deletes all stashes. Cannot be undone - use with caution!
Example: To delete all stashes, run:
git stash clear
git stash show
Stashing🟡 Intermediate
Shows the changes in a stash without applying it. Useful for previewing what's in a stash before applying.
Example: To preview a stash, run:
git stash show stash@{0}
git stash branch [branch_name]
Stashing🔴 Advanced
Creates a new branch and applies a stash to it. Useful if you stashed work and then made conflicting changes.
Example: To apply stash to new branch, run:
git stash branch my-stash-branch
git tag [tag_name]
Tagging🟢 Beginner
Creates a lightweight tag pointing to the current commit. Tags mark specific points in history like release versions.
Example: To create a tag, run:
git tag v1.0.0
git tag -a [tag_name] -m "message"
Tagging🟢 Beginner
Creates an annotated tag (preferred method) with descriptive message, author, and timestamp. More durable than lightweight tags.
Example: To create an annotated tag, run:
git tag -a v1.0.0 -m "Release version 1.0.0"
git tag
Tagging🟢 Beginner
Lists all tags in the repository. Shows all marked releases and versions.
Example: To list all tags, run:
git tag
git tag -l [pattern]
Tagging🟢 Beginner
Lists tags matching a pattern. Useful for filtering tags by version numbers or prefixes.
Example: To list tags matching pattern, run:
git tag -l 'v1.*'
git show [tag_name]
Tagging🟢 Beginner
Shows detailed information about a tag including the tagged commit, tagger, date, and message.
Example: To view tag details, run:
git show v1.0.0
git tag -d [tag_name]
Tagging🟡 Intermediate
Deletes a tag from the local repository. Useful for removing accidentally created or outdated tags.
Example: To delete a tag, run:
git tag -d v1.0.0
git push origin [tag_name]
Tagging🟡 Intermediate
Pushes a specific tag to the remote repository, making it available to other team members and CI/CD systems.
Example: To push a tag, run:
git push origin v1.0.0
git push origin --delete [tag]
Tagging🟡 Intermediate
Deletes a tag from the remote repository. Useful for cleaning up mistagged versions.
Example: To delete a remote tag, run:
git push origin --delete v0.9.0
git push --tags
Tagging🟡 Intermediate
Pushes all local tags to remote at once, without pushing any commits. Useful for publishing all release versions.
Example: To push all tags, run:
git push --tags
git log
History & Inspection🟢 Beginner
Displays commit history of current branch with hash, author, date, and message. Shows newest commits first. Press 'q' to exit.
Example: To view history, run:
git log
git log --oneline
History & Inspection🟢 Beginner
Compact commit history with abbreviated hashes and single-line messages. Quick overview of recent commits.
Example: To see compact history, run:
git log --oneline
git log --graph --oneline --decorate --all
History & Inspection🟡 Intermediate
Visualizes commit history as a graph showing branches and merges. Great for understanding repository structure.
Example: To visualize history graph, run:
git log --graph --oneline --decorate --all
git log -p
History & Inspection🟡 Intermediate
Shows detailed commit history with full diffs (patches) for each commit. Verbose but shows exact line changes.
Example: To see history with diffs, run:
git log -p
git log --stat
History & Inspection🟡 Intermediate
Shows history with statistics: which files changed and how many lines added/removed. Summary view of changes.
Example: To see history with stats, run:
git log --stat
git log --follow [file]
History & Inspection🟡 Intermediate
Shows complete history of a file including renames. Traces file's evolution across name changes.
Example: To see file history with renames, run:
git log --follow index.html
git log --author="[name]"
History & Inspection🟡 Intermediate
Filters commit history to show only commits by a specific author. Useful for finding who made certain changes.
Example: To filter by author, run:
git log --author="Majid Ali"
git log --grep="[pattern]"
History & Inspection🟡 Intermediate
Searches commit messages for pattern matching. Finds commits about specific features, bugs, or keywords.
Example: To search commits, run:
git log --grep="bug fix"
git log --since=[date]
History & Inspection🟡 Intermediate
Shows commits after a specific date. Format: YYYY-MM-DD or relative (2.weeks, 1.month, etc.).
Example: To see commits since date, run:
git log --since=2024-01-01
git log --until=[date]
History & Inspection🟡 Intermediate
Shows commits before a specific date. Can combine with --since for date range queries.
Example: To see commits until date, run:
git log --until=2024-12-31
git log -n [number]
History & Inspection🟢 Beginner
Limits output to the last N commits. Useful for focusing on recent history.
Example: To see last 5 commits, run:
git log -n 5
git show [commit]
History & Inspection🟢 Beginner
Shows detailed information about a specific commit: changes, author, date, and full diff.
Example: To view a commit, run:
git show abcd123
git diff
History & Inspection🟢 Beginner
Shows changes between working directory and last commit. Reveals what you've modified but not staged.
Example: To see unstaged changes, run:
git diff
git diff --cached
History & Inspection🟢 Beginner
Shows differences between staged changes and last commit. Review what's about to be committed.
Example: To see staged changes, run:
git diff --cached
git diff [branch1] [branch2]
History & Inspection🟡 Intermediate
Compares all changes between two branches. Shows what would differ if you merged them.
Example: To compare branches, run:
git diff main feature-branch
git diff [commit1] [commit2]
History & Inspection🟡 Intermediate
Shows differences between two commits. Useful for understanding what changed between versions.
Example: To compare commits, run:
git diff abcd123 efgh456
git diff --name-only [branch1] [branch2]
History & Inspection🟡 Intermediate
Lists only filenames that differ between two branches. Useful for seeing what changed without diffs.
Example: To see changed files only, run:
git diff --name-only main feature
git diff --stat [commit1] [commit2]
History & Inspection🟡 Intermediate
Shows summary of changes between commits with file statistics. Concise view of impact.
Example: To see change statistics, run:
git diff --stat abcd123 efgh456
git shortlog
History & Inspection🟢 Beginner
Summarizes commit history grouped by author with counts. Shows who contributed how much.
Example: To see author summary, run:
git shortlog
git blame [file]
History & Inspection🟡 Intermediate
Shows who last modified each line of a file and in which commit. Useful for understanding code history.
Example: To see line-by-line authors, run:
git blame index.html
git grep [pattern]
History & Inspection🟡 Intermediate
Searches tracked file contents for a pattern. Git-aware version of grep, faster and version-aware.
Example: To search files, run:
git grep "TODO"
git reset [file]
Undoing Changes🟡 Intermediate
Unstages a file from the staging area. Changes remain in working directory - safe operation.
Example: To unstage a file, run:
git reset myfile.txt
git reset --soft [commit]
Undoing Changes🔴 Advanced
Moves HEAD to a previous commit while keeping changes staged. Useful for reorganizing commits.
Example: To soft reset, run:
git reset --soft abcd123
git reset --mixed [commit]
Undoing Changes🔴 Advanced
Moves HEAD and unstages changes. Files remain modified but not staged. Default reset behavior.
Example: To reset and unstage, run:
git reset --mixed abc123
git reset --hard [commit]
Undoing Changes🔴 Advanced
Completely resets to a previous commit, discarding all changes. **Destructive** - use with caution!
Example: To hard reset, run:
git reset --hard abcd123
git revert [commit]
Undoing Changes🟡 Intermediate
Creates a new commit that undoes changes from a previous commit. Safe for shared branches - preserves history.
Example: To undo via revert, run:
git revert abcd123
git checkout -- [file]
Undoing Changes🟡 Intermediate
Discards local changes to a file, restoring it to the last commit. **Destructive** - cannot be undone.
Example: To discard changes, run:
git checkout -- index.html
git restore [file]
Undoing Changes🟡 Intermediate
Modern alternative to 'checkout --'. Restores a file to its committed state, discarding changes.
Example: To restore a file, run:
git restore index.html
git restore --staged [file]
Undoing Changes🟡 Intermediate
Unstages a file without affecting working directory. Modern alternative to 'git reset'.
Example: To unstage (modern way), run:
git restore --staged myfile.txt
git clean -df
Undoing Changes🔴 Advanced
Removes untracked files and directories. **Destructive** - use 'git clean -dn' to preview first!
Example: To remove untracked files, run:
git clean -df
git clean -dn
Undoing Changes🟡 Intermediate
Shows what untracked files would be deleted without actually deleting. Safe preview for 'git clean -df'.
Example: To preview deletion, run:
git clean -dn
git rm --cached -r [directory]
Staging & Committing🟡 Intermediate
Stops tracking a directory in Git without deleting it locally. Useful for removing accidentally tracked folders.
Example: To stop tracking directory, run:
git rm --cached -r dev-dist/
git rev-parse HEAD
Repository Information🟡 Intermediate
Returns the full commit hash of the current HEAD. Useful for scripts and CI/CD automation.
Example: To get current commit hash, run:
git rev-parse HEAD
git rev-parse --short HEAD
Repository Information🟡 Intermediate
Returns abbreviated (7-char) version of current commit hash. More readable for display.
Example: To get short hash, run:
git rev-parse --short HEAD
git rev-parse --abbrev-ref HEAD
Repository Information🟡 Intermediate
Returns the name of the current branch. Useful for scripts needing to know current branch.
Example: To get branch name, run:
git rev-parse --abbrev-ref HEAD
git describe --tags
Repository Information🟡 Intermediate
Shows the most recent tag reachable from current commit. Useful for determining version.
Example: To find nearest tag, run:
git describe --tags
git ls-files
Repository Information🟡 Intermediate
Lists all files currently tracked by Git. Useful for seeing what's under version control.
Example: To see tracked files, run:
git ls-files
git symbolic-ref HEAD
Repository Information🔴 Advanced
Shows what branch HEAD is pointing to. Returns current branch reference.
Example: To see HEAD reference, run:
git symbolic-ref HEAD
git name-rev [commit]
Repository Information🔴 Advanced
Shows human-readable name for a commit relative to tags/branches. Useful for commit description.
Example: To get readable name, run:
git name-rev abcd123
git reflog
Repository🔴 Advanced
Shows log of all HEAD movements: commits, resets, rebases, etc. Useful for recovering lost commits.
Example: To view operation history, run:
git reflog
git fsck --lost-found
Repository🔴 Advanced
Scans for lost commits and objects in the repository. Can help recover work lost to resets.