git add command

Git add command explained with examples. After a developer completes a software product’s functionality, the next step is to publish all changes into the repository. All modified and newly created files should be staged for the next commit. The git “add” command creates a staging area that contains updated, added, and deleted files. Adding a new file to Git, an step by step example. Step-1: Create a new file named addExampleFile.c in the working tree using vim or other ways. Step-2: The file has been created and untracked by git. Step-3: With the help of the git add command, let’s make the local repository aware of this new file. Step-4: Using git commit, add the code changes to the repository. Step -5: With the git push command, propagate the changes to the remote repository. All options in git add commands are explained. This section will cover all options available in the git add command, along with a practical example for each. Add individual files or directories (file-path/directory). If you specify the full path to the file, the file will get added, and if you specify the directory path, all files in the directory will be added. You can specify multiple files or directories separated by space as command-line options. Add everything to the staging area with the –all option for the next commit. Using this option will add all changes inside the project for the next commit. Any deleted or modified files, as well as new files, will be added. However, be aware that this may add unwanted files, such as swap files, binaries, tags on Linux, etc. Add changes only to files that have been tracked (-u). It adds all the changes to the staging area. A change includes either modified files or deleted files. The untracked files remain untouched.