This is a cheat sheet of 100 commonly used commands in Git Bash, organized from basic to advanced, and from most used to least used. Each command includes a short explanatory comment.
git init# Initialize a new Git repositorygit config user.name "<name>"# Set your Git usernamegit config user.email "<email>"# Set your Git emailgit status# Check the status of your repogit add <file># Add a file to the staging areagit add .# Add all files to the staging areagit commit -m "<message>"# Commit changes with a messagegit log# View commit historygit log --oneline# View commit history in compact formatgit diff# Show changes between working directory and the last commitgit diff <branch1> <branch2># Show changes between two branchesgit show <commit># Show changes made in a specific commitgit 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
git remote add origin <url># Connect local repo to remotegit push -u origin <branch># Push changes to remote branchgit pull# Pull changes from remote repogit clone <url># Clone a remote repositorygit remote -v# List remote connectionsgit remote rm <remote># Remove a remote connectiongit fetch# Fetch updates from remote repo without merginggit remote show <remote># Show details about a remote repositorygit remote rename <old-name> <new-name># Rename a remote repositorygit push --tags# Push all tags to remote repositorygit push --force# Force-push changes to the remote repositorygit push origin --delete <branch># Delete a remote branchgit pull --rebase# Pull and rebase the current branchgit fetch --all# Fetch updates from all remote repositoriesgit remote update# Update remote-tracking branches
git branch# List all branchesgit branch <branch># Create a new branchgit checkout <branch># Switch to a branchgit checkout -b <branch># Create and switch to a new branchgit merge <branch># Merge a branch into the current branchgit branch -d <branch># Delete a branchgit branch -r# List remote branchesgit branch -a# List local and remote branchesgit branch -u <upstream-branch># Set upstream branch for the current branchgit branch -m <old-name> <new-name># Rename a branchgit branch --merged# List branches that have been merged into the current branchgit branch --no-merged# List branches that have not been merged into the current branchgit merge --abort# Abort an ongoing merge operationgit merge --squash <branch># Squash the commits from a branch into a single commitgit merge --no-ff <branch># Merge with a merge commit even if it's a fast-forward merge
git stash# Save changes for latergit stash list# List stashed changesgit stash apply# Apply stashed changesgit stash drop# Remove a stashgit stash pop# Apply and remove the latest stashgit stash branch <branch># Create a new branch and apply a stashgit stash save "<message>"# Save changes with a custom stash messagegit stash clear# Remove all stashed changesgit stash apply <stash># Apply a specific stashgit stash drop <stash># Remove a specific stash
git fetch# Fetch updates from remote repogit rebase <branch># Rebase current branch onto anothergit cherry-pick <commit># Apply a specific commitgit rebase --abort# Abort an ongoing rebase operationgit rebase --continue# Continue a paused rebase operationgit rebase --skip# Skip a conflicting commit during rebasegit cherry-pick --continue# Continue a paused cherry-pick operationgit cherry-pick --abort# Abort an ongoing cherry-pick operation
git reset# Reset staging area to match the last commitgit reset <file># Remove a file from the staging areagit reset --hard# Discard all changes since the last commitgit 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
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
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 config --list# List all Git configuration settingsgit help <command># Show help for a Git command