git add command
The git addcommand is used to add file contents or updates the current content of the working tree to the staging area (so, the staging area contains a snapshot of the working tree data). Every time we add or update any file in our project, it is required to forward updates to the staging area.
Note: The git add command can be run many times before making a commit. These all add operations can be put under one commit.
Syntax 1. To add one file git add <file-name> Example:
Bash
2. To add more than one file separate file names with space git add newfile1.txt newfile2.txt 3. Add all the files To add all the files from the repository, run the add command with -A option. We can use '.' Instead of -A option. git add -A Or
git add .
4. Add Files by Wildcard Git allows us to add all the same pattern files at once. It is another way to add multiple files together. Suppose I want to add all java files or text files, then we can use pattern .java or .txt. To do so, we will run the command as follows: Example:
Bash
The above command will stage all the text files.
Life cycle of file status in git
![git add command git add command](media/git-add-01.png)