git config --global user.name "Your Name"

Configuration🟢 Beginner

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.

Example: To set your username globally, run:

git config --global user.name "John Doe"

git config --global user.email "your_email@example.com"

Configuration🟢 Beginner

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

Example: To clone a repository from GitHub, run:

git clone https://github.com/Majid-Ali-Watto/Git-factory.git

git clone [url] [directory]

Repository🟢 Beginner

Clones a repository into a custom directory with a name of your choice instead of using the repository's default name.

Example: To clone into a folder named 'my-project', run:

git clone https://github.com/user/repo.git my-project

git clone --depth 1 [url]

Repository🟡 Intermediate

Creates a shallow clone with only the latest commit history. Much faster and smaller download, useful when you don't need full history.

Example: To do a shallow clone, run:

git clone --depth 1 https://github.com/user/repo.git

git clone --mirror [url]

Repository🔴 Advanced

Creates a bare mirror of a repository (no working directory). Used for backing up or duplicating repositories.

Example: To create a mirror clone, run:

git clone --mirror https://github.com/user/repo.git repo.git

git init

Repository🟢 Beginner

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.

Example: To create an empty commit, run:

git commit --allow-empty -m "Trigger CI/CD pipeline"

git branch

Branching🟢 Beginner

Lists all local branches. The current branch is marked with an asterisk (*). Does not show remote branches.

Example: To see all local branches, run:

git branch

git branch -a

Branching🟢 Beginner

Lists all branches: both local and remote-tracking branches. Gives complete picture of all branches in the repository.

Example: To see all branches, run:

git branch -a

git branch -r

Branching🟢 Beginner

Lists only remote-tracking branches. Shows branches that exist on the remote repository but may not be checked out locally.

Example: To see only remote branches, run:

git branch -r

git branch [branch_name]

Branching🟢 Beginner

Creates a new branch at the current commit. Does not switch to the new branch - you'll need to 'checkout' to start using it.

Example: To create a new branch, run:

git branch feature-new-ui

git branch -d [branch_name]

Branching🟡 Intermediate

Safely deletes a branch only if it has been fully merged. Git refuses to delete if there are unmerged commits, protecting you from losing work.

Example: To delete a merged branch, run:

git branch -d feature-login

git branch -D [branch_name]

Branching🟡 Intermediate

Forcefully deletes a branch regardless of merge status. **Destructive** - use only when absolutely sure you want to lose that branch.

Example: To force delete a branch, run:

git branch -D experimental-feature

git branch -m [old_name] [new_name]

Branching🟡 Intermediate

Renames a branch. If you're on the branch you want to rename, you can omit the old name.

Example: To rename a branch, run:

git branch -m old-name new-name

git branch -M main

Branching🟡 Intermediate

Renames the current branch to 'main', forcefully overwriting if 'main' exists. Useful for changing default branch names.

Example: To rename current branch to main, run:

git branch -M main

git branch --contains [commit]

Branching🟡 Intermediate

Lists all branches that contain a specific commit. Helpful for finding which releases or branches include a particular change.

Example: To find branches with a commit, run:

git branch --contains abcd123

git checkout [branch_name]

Branching🟢 Beginner

Switches your working directory to a different branch. Updates all files to match that branch's latest commit.

Example: To switch to an existing branch, run:

git checkout feature-new-ui

git checkout -b [branch]

Branching🟢 Beginner

Creates a new branch and immediately switches to it. Shortcut combining 'branch' and 'checkout' in one command.

Example: To create and switch to a new branch, run:

git checkout -b feature-user-profile

git switch [branch_name]

Branching🟢 Beginner

Modern alternative to 'checkout' for switching branches. Cleaner syntax dedicated specifically to branch switching.

Example: To switch branches using modern syntax, run:

git switch feature-new-ui

git switch -c [branch]

Branching🟢 Beginner

Modern equivalent of 'checkout -b'. Creates and switches to a new branch using newer, cleaner Git syntax.

Example: To create and switch using modern syntax, run:

git switch -c feature-notifications

git checkout -

Branching🟢 Beginner

Switches to the previously checked-out branch. Quick way to toggle between two branches without typing the full name.

Example: To switch to the last branch, run:

git checkout -

git remote add [name] [url]

Remote🟢 Beginner

Connects your repository to a remote repository with a given name (usually 'origin'). Enables pushing and pulling from that remote.

Example: To add a remote repository, run:

git remote add origin https://github.com/user/repo.git

git remote -v

Remote🟢 Beginner

Lists all configured remotes with their fetch and push URLs. Shows where your code is being pushed to and pulled from.

Example: To view all remotes, run:

git remote -v

git remote show [remote_name]

Remote🟡 Intermediate

Displays detailed information about a remote: branches, tracking configuration, and current status.

Example: To see remote details, run:

git remote show origin

git remote rm [name]

Remote🟡 Intermediate

Removes a remote repository connection from your local configuration. Does not affect the actual remote repository.

Example: To remove a remote, run:

git remote rm old-remote

git remote rename [old_name] [new_name]

Remote🟡 Intermediate

Renames a remote connection in your configuration. Useful when changing how you reference a remote.

Example: To rename a remote, run:

git remote rename origin upstream

git remote set-url [remote_name] [new_url]

Remote🟡 Intermediate

Changes the URL of an existing remote. Useful when migrating repositories or switching between HTTPS and SSH.

Example: To change a remote URL, run:

git remote set-url origin https://github.com/new-user/new-repo.git

git push -u origin [branch]

Remote🟢 Beginner

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.

Example: To find lost commits, run:

git fsck --lost-found

git gc

Repository🔴 Advanced

Garbage collection - removes unreachable objects and optimizes database. Improves performance.

Example: To optimize repository, run:

git gc

git bisect start

Debugging🔴 Advanced

Initiates binary search to find which commit introduced a bug. Interactive process marking commits good/bad.

Example: To start bisecting, run:

git bisect start

git bisect bad

Debugging🔴 Advanced

Marks current commit as 'bad' during bisect. Continues searching in earlier history.

Example: During bisect, mark as bad:

git bisect bad

git bisect good

Debugging🔴 Advanced

Marks current commit as 'good' during bisect. Continues searching in later history.

Example: During bisect, mark as good:

git bisect good

git bisect reset

Debugging🔴 Advanced

Ends bisect session and returns to original branch. Use after finding problematic commit.

Example: To end bisect, run:

git bisect reset

git archive [branch] --format=zip --output=[file.zip]

Repository🔴 Advanced

Creates zip archive of a branch without .git directory. Useful for distributing clean versions.

Example: To create archive, run:

git archive main --format=zip --output=project.zip

git mv [old_path] [new_path]

Repository🟡 Intermediate

Moves or renames a file while preserving Git history. Automatically stages the change.

Example: To move/rename file, run:

git mv old-name.txt new-name.txt

git submodule add [repo_url] [path]

Advanced🔴 Advanced

Adds external Git repository as submodule. Includes another repo in your project while keeping it separate.

Example: To add submodule, run:

git submodule add https://github.com/user/repo.git path/to/sub

git submodule init

Advanced🔴 Advanced

Initializes submodules from .gitmodules file. Required before pulling submodule content.

Example: To init submodules, run:

git submodule init

git submodule update

Advanced🔴 Advanced

Fetches and checks out correct commits for submodules. Ensures submodules match main repository.

Example: To update submodules, run:

git submodule update

git submodule foreach git pull

Advanced🔴 Advanced

Runs git pull in every submodule directory. Updates all submodules at once.

Example: To update all submodules, run:

git submodule foreach git pull

git worktree add [path] [branch]

Advanced🔴 Advanced

Creates new working tree for multiple branches simultaneously. Work in different directories on different branches.

Example: To create working tree, run:

git worktree add ../bug-fix main

git worktree list

Advanced🔴 Advanced

Lists all working trees created for this repository. Shows paths and branch information.

Example: To view working trees, run:

git worktree list

git worktree remove [path]

Advanced🔴 Advanced

Removes a working tree. Cleans up directory and removes worktree reference.

Example: To remove working tree, run:

git worktree remove ../bug-fix

git format-patch -n HEAD

Advanced🔴 Advanced

Creates patch files from last N commits. Useful for emailing changes or applying to other repos.

Example: To create patches, run:

git format-patch -1 HEAD

git apply [patch_file]

Advanced🔴 Advanced

Applies changes from patch file to working directory. Git-aware version of patch command.

Example: To apply patch, run:

git apply fix.patch

git am [patch_file]

Advanced🔴 Advanced

Applies patch and creates commit with original author/date metadata. Preserves patch commit info.

Example: To apply patch as commit, run:

git am fix.patch

git cat-file -p [object]

Advanced🔴 Advanced

Displays contents of a Git object. Useful for understanding Git's internal structure.

Example: To view Git object, run:

git cat-file -p abcd123

git hash-object [file]

Advanced🔴 Advanced

Calculates Git hash for a file without staging/committing. Useful for comparing versions.

Example: To calculate hash, run:

git hash-object index.html

git verify-commit [commit]

Advanced🔴 Advanced

Verifies GPG signature of a commit. Ensures commit authenticity in secure environments.

Example: To verify signature, run:

git verify-commit abcd123

git filter-branch

Advanced🔴 Advanced

Rewrites Git history. Advanced tool for removing sensitive data or restructuring. **Affects other developers!**

Example: To filter history, run:

git filter-branch --tree-filter 'rm -f secrets.txt'

git for-each-ref

Advanced🔴 Advanced

Lists all refs (branches, tags, remotes) with custom output format. Powerful for scripting.

Example: To list refs, run:

git for-each-ref --sort=version:refname

git update-index --assume-unchanged [file]

Configuration🔴 Advanced

Tells Git to ignore changes to a file without removing it from version control. Useful for configs.

Example: To ignore file changes, run:

git update-index --assume-unchanged config.json

git update-index --no-assume-unchanged [file]

Configuration🔴 Advanced

Resumes tracking changes to a file marked with --assume-unchanged.

Example: To resume tracking, run:

git update-index --no-assume-unchanged config.json

git help [command]

Help & Documentation🟢 Beginner

Opens documentation for a specific Git command. Provides comprehensive help within terminal.

Example: To get help, run:

git help commit

git --version

Help & Documentation🟢 Beginner

Displays your installed Git version. Useful for checking compatibility and features.

Example: To check version, run:

git --version