Git Commands
Essential Git commands for version control
Version Control
Setup & Config
git initInitialize a new Git repository
git clone <url>Clone a repository
git config --global user.name "Name"Set username
git config --global user.email "email"Set email
Basic Commands
git statusCheck working directory status
git add <file>Stage a file
git add .Stage all changes
git commit -m "message"Commit with message
git pushPush to remote
git pullPull from remote
Branching
git branchList branches
git branch <name>Create new branch
git checkout <branch>Switch to branch
git checkout -b <name>Create and switch to branch
git merge <branch>Merge branch into current
git branch -d <name>Delete branch
History & Diff
git logView commit history
git log --onelineCompact commit history
git diffShow unstaged changes
git diff --stagedShow staged changes
git show <commit>Show commit details
Undo & Reset
git restore <file>Discard changes in file
git reset HEAD <file>Unstage a file
git reset --soft HEAD~1Undo last commit, keep changes
git reset --hard HEAD~1Undo last commit, discard changes
git revert <commit>Create new commit that undoes changes
Stash
git stashStash current changes
git stash listList all stashes
git stash popApply and remove latest stash
git stash applyApply latest stash, keep it
git stash dropRemove latest stash