Git Add File to Repository
Use git add command to add new files to local git repository. This command will not add ignored files by default, also skipped files silently found in the recursive run. The command will throw an error for the files explicitly specified on the command line.
Syntax:
git add [FILENAMES]
Dry run for Git Add
This option doesn’t actually add the file(s). You can use -n
or --dry-run
to test files if they exist and/or will be ignored with git add
command.
git add . --dry-run
Examples of Git Add Files
You can also specify file names with git add
c a mmand to add specific file. Use the following example command to add README by specifying names.
git add index.html README
Also, you can use wildcard names to add files. For example to add all the files with the .txt extension from Documents directory.
git add Documents/\*.txt
You can also specify dot (.) to add all the files, directories, and sub-directories. This is useful while adding multiple files.
git add .