Git Add
Once you’ve made changes in your project, the next step is to stage those changes using git add
. This prepares them to be included in your next commit.
What Does Git Add
Do?
Git add
moves changes from the Working Directory to the Staging Area. If you edit a file and don’t run git add, the changes will not be added to your next commit.
Examples
Add a single file
git add <filename>
Add multiple files
git add file1.txt file2.txt
Add all changes
git add .
Add all changes (including deletions)
git add -A
Add Your First Change
- Open terminal and navigate to the
git-101
repo
cd projects/git-101
- Create a file:
echo "Hello Git" > message.txt
- Check the status:
git status
Output:
Untracked files:
message.txt
- Stage the file:
git add message.txt
- Check status again:
git status
Output:
Changes to be committed:
new file: message.txt