Git for Development¶
Setup (One-time)¶
Starting a Project¶
Working with Files¶
git status # Show changes
git add <file> # Stage a file
git add . # Stage all changes
git reset <file> # Unstage a file
git diff # Show unstaged changes
git diff --staged # Show staged changes
Commit Changes¶
git commit -m "Message" # Commit staged changes
git commit -am "Message" # Stage + commit tracked files
Branching¶
git branch # List branches
git branch <name> # Create branch
git checkout <name> # Switch branch
git checkout -b <name> # Create & switch
git merge <branch> # Merge into current branch
Remote Repositories¶
git remote -v # Show remotes
git remote add origin <url> # Add remote repo
git push -u origin main # Push main branch first time
git push # Push changes
git pull # Fetch + merge changes
git fetch # Fetch without merge
Undoing Mistakes¶
git restore <file> # Discard changes
git reset --soft HEAD~1 # Undo last commit, keep changes
git reset --hard HEAD~1 # Undo last commit, discard changes
git revert <commit-id> # Revert a commit safely
Logs & History¶
git log # Full commit history
git log --oneline --graph # Compact branch history
git show <commit-id> # Show details of a commit
Stash (Save work temporarily)¶
git stash # Save uncommitted changes
git stash list # Show stashes
git stash apply # Reapply last stash
git stash drop # Remove last stash
Tags (Versions)¶
Quick Workflow Example