Quick reference for common Git commands with copy functionality.
git initInitialize a new Git repository
git clone <url>Clone a repository from remote URL
Example: git clone https://github.com/user/repo.git
git config --global user.name "<name>"Set global username
Example: git config --global user.name "John Doe"
git config --global user.email "<email>"Set global email
Example: git config --global user.email "john@example.com"
git config --listShow all Git configuration settings
git statusShow working tree status
git add <file>Add file to staging area
Example: git add index.html
git add .Add all changes to staging area
git add -AAdd all changes including deletions
git commit -m "<message>"Commit staged changes with message
Example: git commit -m "Add login feature"
git commit -am "<message>"Stage and commit all modified files
Example: git commit -am "Fix bug"
git rm <file>Remove file from working tree and staging
git mv <old> <new>Move or rename a file
git branchList all local branches
git branch -aList all branches including remote
git branch <name>Create a new branch
Example: git branch feature-login
git checkout <branch>Switch to a branch
Example: git checkout main
git checkout -b <name>Create and switch to new branch
Example: git checkout -b feature-login
git switch <branch>Switch to a branch (modern syntax)
Example: git switch main
git switch -c <name>Create and switch to new branch
Example: git switch -c feature-login
git branch -d <name>Delete a merged branch
Example: git branch -d feature-login
git branch -D <name>Force delete a branch
Example: git branch -D feature-login
git rename -m <new>Rename current branch
Example: git branch -m new-name
git merge <branch>Merge a branch into current branch
Example: git merge feature-login
git merge --no-ff <branch>Merge with a merge commit
git rebase <branch>Reapply commits on top of another branch
Example: git rebase main
git rebase -i <branch>Interactive rebase for editing commits
git cherry-pick <commit>Apply a specific commit to current branch
Example: git cherry-pick abc123
git remote -vShow remote repositories
git remote add <name> <url>Add a remote repository
Example: git remote add origin https://github.com/user/repo.git
git fetchDownload objects and refs from remote
git fetch <remote>Fetch from specific remote
Example: git fetch origin
git pullFetch and merge from remote
git pull --rebaseFetch and rebase instead of merge
git pushPush commits to remote
git push -u origin <branch>Push and set upstream branch
Example: git push -u origin main
git push origin --delete <branch>Delete remote branch
Example: git push origin --delete feature-login
git logShow commit history
git log --onelineShow concise commit history
git log --graph --oneline --allShow visual branch history
git log -n <number>Show last N commits
Example: git log -n 5
git diffShow unstaged changes
git diff --stagedShow staged changes
git diff <commit1> <commit2>Show diff between two commits
git show <commit>Show details of a specific commit
Example: git show abc123
git blame <file>Show who changed each line
Example: git blame index.js
git restore <file>Discard changes in working directory
git restore --staged <file>Unstage a file
git reset HEAD~1Undo last commit, keep changes staged
git reset --soft HEAD~1Undo last commit, keep changes
git reset --hard HEAD~1Undo last commit and discard changes
git revert <commit>Create a new commit that undoes a commit
Example: git revert abc123
git clean -fdRemove untracked files and directories
git stashStash changes for later
git stash push -m "<message>"Stash with a message
git stash listList all stashes
git stash popApply and remove latest stash
git stash applyApply latest stash without removing
git stash dropRemove latest stash
git stash clearRemove all stashes