📦 git add = Stage Changes
Changed files need staging. git add stages changes for commit. Select what to commit, commit later.
📝 Git Add Commands
# Stage all changes git add . # Stage specific file git add file.txt # Stage multiple files git add file1.txt file2.txt # Stage all .js files git add *.js # Stage interactive (choose changes) git add -i # Stage patch (part of file) git add -p # Stage with interactive patch git add -p file.txt # Stage all files (including new) git add -A # Stage all files (except .gitignore) git add .
🎯 Interactive Staging
# Interactive mode git add -i # Patch mode (stage specific changes) git add -p file.txt # y - stage this hunk # n - don't stage this hunk # s - split this hunk # e - manually edit hunk # q - quit # Stage only specific lines git add -p # Unstage file git reset HEAD file.txt # View staged changes git diff --staged
💡 Workflow
- Make changes to files
- git status (see changed files)
- git add (stage changes)
- git status (verify staged)
- git commit -m “message” (commit)
“git add stages changes. git add -p stages specific lines. Essential for selective commits.”
