git config --global user.name "Your Name" # Set your Git username
git config --global user.email "you@email.com" # Set your Git email
git config --list # Show all Git configs
git config --global core.editor "code --wait" # Set default editorgit init # Initialize a new Git repository
git clone <repo-url> # Clone a remote repository
git clone -b <branch> <url> # Clone a specific branchgit status # Show current changes (staged/unstaged)
git log # Show full commit history
git log --oneline # Show compact commit history
git log --graph --oneline # Visual commit graph
git show <commit-id> # Show details of a commitgit add <file> # Stage a specific file
git add . # Stage all changes
git commit -m "message" # Commit staged changes
git commit -am "message" # Stage + commit (equivalent to: git add -u && git commit)git diff # Show unstaged changes
git diff --staged # Show staged changes
git diff <branch1>..<branch2> # Compare two branchesgit branch # List branches
git branch <name> # Create new branch
git switch <branch> # Switch to branch
git switch -c <name> # Create + switch branch
git checkout <branch> # Old way to switch branch
git checkout -b <name> # Old way create + switch
git branch --merged # Show branches already merged into current branch
git branch --no-merged # Show branches NOT yet merged
git branch -d <branch> # Delete a local branch (safe: only if merged)
git branch -D <branch> # Force delete a local branch (even if not merged)
git push origin --delete <branch> # Delete a remote branchgit merge <branch> # Merge branch into current branch
git rebase <branch> # Reapply commits on top of another branch
git rebase -i HEAD~3 # Interactive rebase (edit last 3 commits)git remote # List remote names
git remote -v # Show remote URLs
git remote add origin <url> # Add remote repository
git remote remove origin # Remove remote
git remote rename old new # Rename remote
git remote set-url origin <url> # Change remote URL
git remote set-url --add origin <url> # Add another URL to remote
git remote set-url --delete origin <url> # Remove specific URL
git fetch # Fetch changes from remote
git fetch origin # Fetch from specific remote
git fetch --all # Fetch all remotes
git pull origin main # Fetch + merge from remote branch
git push origin main # Push to remote branch
git push -u origin main # Push and set upstreamgit restore <file> # Discard changes in file
git restore --staged <file> # Unstage file
git reset HEAD <file> # Unstage file (older way)
git reset --soft HEAD~1 # Undo commit (keep changes)
git reset --hard HEAD # Reset everything (danger) | Undo commit (remove changes)
git revert <commit-id> # Undo commit safely (creates new commit)git stash # Save changes temporarily
git stash list # List stashes
git stash apply # Apply stash
git stash pop # Apply + remove stash
git stash drop # Delete stashgit tag # List tags
git tag v1.0 # Create lightweight tag
git tag -a v1.0 -m "msg" # Create annotated tag
git push origin v1.0 # Push taggit grep "text" # Search text in repo
git log --grep="msg" # Search commit messages
git blame <file> # Show who changed each line
git reflog # Show all HEAD movementsgit cherry-pick <commit-id> # Apply commit from another branch
git bisect # Find buggy commitgit clean -f # Remove untracked files
git clean -fd # Remove files + directoriesgit submodule add <repo> # Add submodule
git submodule update --init --recursive # Initialize submodulesIf you remember just these, you’re become productive:
git clone <url> # Get repo
git status # Check changes
git add . # Stage changes
git commit -m "msg" # Save changes
git pull # Get latest updates
git push # Upload changes
git switch -c feature # New branch
git merge feature # Merge branch
git log --oneline # View history