git add
Stage changes so they go into the next commit
What it does
A commit does not save every changed file, only what is in the index (also called the staging area). git add puts changes there: one file, a folder, or everything at once.
This lets you build a commit from just the changes you want and leave the rest for later. The index keeps the file as it was when you ran git add: if the file changes again, stage the new edits too.
Syntax
git add <file>…
git add .Examples
Stage every change in the current folder
git add .add— add to the index (prepare for a commit).— the whole current folder
Stage only the file src/app.js
git add src/app.jsadd— add to the indexsrc/app.js— a specific file
Related commands
- git status — See what changed in the folder and what is already staged
- git commit — Save the staged changes to history as a new commit
- git restore — Discard edits in a file or unstage it