Git Bash Commands Cheat Sheet
Inspect & Compare
Traking Path Changes
git ls-files
# List all files tracked by Gitgit blame <file>
# Show who changed what in a filegit bisect
# Find the commit that introduced a buggit reflog
# Show a log of all local commitsgit cat-file -p <commit>
# Display the content of a commit objectgit rev-parse <ref>
# Get the SHA-1 hash of a referencegit fsck
# Verify the integrity of the repositorygit gc
# Clean up unnecessary files and optimize the repository
Remove, and Rename
git rm <file>
# Remove a file from the repository and working directorygit mv <old-name> <new-name>
# Rename or move a filegit clean -f
# Remove untracked files from the working directorygit clean -fd
# Remove untracked files and directories from the working directory
Tags
git tag
# List tagsgit tag <tag-name>
# Create a lightweight taggit tag -a <tag-name> -m "<message>"
# Create an annotated taggit push origin <tag-name>
# Push a tag to the remote repositorygit tag -d <tag-name>
# Delete a local taggit push origin --delete <tag-name>
# Delete a remote taggit tag --contains <commit>
# Find tags containing a specific commitgit describe
# Describe the most recent tag and commit
Advanced Commands
git submodule add <repository> <path>
# Add a Git submodulegit submodule init
# Initialize Git submodulesgit submodule update
# Update Git submodulesgit submodule foreach <command>
# Execute a command in all submodulesgit grep <pattern>
# Search for a pattern in the repositorygit log -S"<pattern>"
# Search for commits that added or removed a patterngit archive --format=zip --output=<output-file> <branch>
# Create a zip archive of a branchgit shortlog
# Summarize commit logs by authorgit log --graph --decorate --oneline
# Display commit history as a graphgit rev-list --count <ref>
# Count the number of commits in a branchgit commit --amend
# Modify the last commitgit commit --amend -m "<new-message>"
# Modify the last commit messagegit reflog expire --expire=now --all
# Remove all reflog entriesgit rev-parse --show-toplevel
# Show the root directory of the repositorygit config --global alias.<alias-name> '<git-command>'
# Create a Git aliasgit help <command>
# Show help for a Git command