What is Git?
Git is a free, open-source distributed version control system (VCS) designed by Linus Torvalds in 2005. It tracks changes in source code during software development and enables multiple developers to collaborate efficiently on projects of any size.
Unlike centralized VCS tools, every Git clone is a full repository with complete history — making it fast, reliable, and offline-capable.
Git Commands Cheatsheet
Setup & Configuration
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global core.editor "code --wait" # VS Code as editor
git config --list # View all configCreating & Cloning
git init # Initialize new repository
git clone # Clone existing repository
git clone my-folder # Clone into specific folder Staging & Committing
git status # Show working directory status
git add # Stage a specific file
git add . # Stage all changes
git add -p # Stage changes interactively
git commit -m "message" # Commit staged changes
git commit -am "message" # Stage tracked files and commit
git commit --amend # Modify the last commit Branching
git branch # List local branches
git branch -a # List all branches (local + remote)
git branch # Create new branch
git checkout # Switch to branch
git checkout -b # Create and switch to branch
git switch # Switch branch (modern syntax)
git switch -c # Create and switch (modern syntax)
git branch -d # Delete merged branch
git branch -D # Force delete branch
git merge # Merge branch into current
git rebase # Rebase current onto branch Remote Repositories
git remote -v # List remotes with URLs
git remote add origin # Add remote
git remote set-url origin # Change remote URL
git push origin # Push branch to remote
git push -u origin # Push and set upstream
git pull # Fetch and merge
git fetch # Fetch without merging
git pull --rebase # Pull with rebase History & Diff
git log # Full commit history
git log --oneline --graph # Compact graph view
git log --author="Name" # Filter by author
git diff # Unstaged changes
git diff --staged # Staged changes
git blame # Who changed each line
git show # Show commit details Undoing Changes
git restore # Discard working directory changes
git restore --staged # Unstage a file
git reset --soft HEAD~1 # Undo last commit, keep changes staged
git reset --mixed HEAD~1 # Undo last commit, keep changes unstaged
git reset --hard HEAD~1 # Undo last commit, discard changes
git revert # Create new commit that undoes a commit Stashing
git stash # Stash current changes
git stash push -m "description" # Stash with a message
git stash list # List all stashes
git stash pop # Apply latest stash and remove it
git stash apply stash@{0} # Apply specific stash
git stash drop stash@{0} # Delete specific stashTags
git tag # List tags
git tag v1.0.0 # Create lightweight tag
git tag -a v1.0.0 -m "Release" # Create annotated tag
git push origin v1.0.0 # Push tag to remote
git push --tags # Push all tags