Add
Anonymous contributor
Published Nov 4, 2021Updated Mar 5, 2022
Contribute to Docs
In Git, adding is used to add changes from the working tree to the staging area. This is where changes are saved for the next commit. When the file name appears in green, it indicates that the file is tracked and will be staged for the next commit.
Example
Below is a short example of how the git add
command works. Assuming a change was saved in a message.txt text file, running git status
will show this:
$ git statusOn branch mainNo commits yetUntracked files:(use "git add <file>..." to include in what will be committed)message.txtnothing added to commit but untracked files present (use "git add" to track)
Since the file is untracked, git add
can be used to stage it for the next commit. Afterwards, running git status
again should yield the following:
$ git add message.txt$ git statusOn branch mainNo commits yetChanges to be committed:(use "git rm --cached <file>..." to unstage)new file: message.txt
The file now appears in green when running git status
, indicating that it is staged and will be saved with the next commit.
There are many extensions to the git add
command such as:
-n
: Where the file will not be added to the staging area but will show whether or not the file exists and/or if it will be ignored.-f
: Which stages all files including those which are ignored..
: Which stages all the files in the current directory. On the command line, it references the current directory.-A
: Which stages all the files in the current directory as well as subdirectories.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Git on Codecademy
- Course
Learn Git & GitHub
Use our beginner friendly Git course to integrate Git and GitHub and manage versions of your projects using Git branches.With CertificateBeginner Friendly4 hours - Course
Learn the Command Line
Learn about the command line, starting with navigating and manipulating the file system, and ending with redirection and configuring the environment.With CertificateBeginner Friendly4 hours