Git CLI Cheat Sheet
Configuration
Configure user name and email
Set automatic command line coloring
Show the global git configuration
Repository Creation & Cloning
Initialize a new git repository
Clone a remote repository to your local machine
Basic Workflow
Add changes to the staging area
Commit changes with a message
Check the status of your repository
Show changes between working directory and staging
Show changes staged but not yet committed
Delete file from project and stage removal for commit
Remote Repositories
List all remote repositories and their URLs
Add a remote repository (Use SSH URLs for remotes to enhance security)
Fetch changes from a remote repository
Fetch and merge changes from a remote repository
Push changes to a remote repository
Reset local repository to match remote
Branching & Merging
List all branches in the repository
Create a new branch
Switch to a different branch
Create and switch to a new branch
Merge changes from one branch into another
Rebase changes interactively
Squash multiple (3) commits into one
Undoing Changes
Discard changes in the working directory
Unstage changes
Undo the last commit (local)
Undo the last commit and discard changes
Change the commit message of the last commit
Revert to a previous commit
Unstage files staged for commit
Tagging
Create a lightweight tag
Create an annotated tag
Push tags to a remote repository
Stashing Changes
Stash changes in the working directory
Stash changes with a custom message
List all stashes
Apply the most recent stash without removing it
Apply the and remove the most recent stash
Cherry-Picking
Apply changes from a specific commit
Apply changes, include a reference to original commit
History & Logs
View the commit history
Show concise commit history
Show the commit history with references
Miscellaneous
Show the git version
Clean untracked files and directories
Add all and insert them in the latest commit
Ignoring Files
Create or edit the .gitignore file