How To Add Changes To A Git Repository With The 'git add' Command

git add command syntax, examples, and code.

TL;DR

Use git add . to add all changes in the current directory

Written by @bazamel_

Image cover

The git add command is used to stage changes in a Git repository. It tells Git to track changes made to a file or a group of files and prepare them to be committed. The changes can be new files, modifications to existing files, or deletions of files.

Here is the basic syntax of the git add command:

git add a_file_path

a_file_path: The name of the file or files that you want to stage. You can specify multiple files by separating them with a space.

For example, if you want to stage changes made to a file called main.c, you would use the following command:

git add main.c

You can also stage all changes made in the current directory by using the . wildcard, like this:

git add .

You can also use the git add command to stage changes to specific directories, like this:

git add a_directory_path

It is important to note that the git add command only stages the changes, it does not actually commit them. To commit the changes, you will need to use the git commit command.

It’s good practice to use git add command in two steps process one is git add and second is git commit, this way you can review the changes before committing them, and also you can commit specific changes rather than committing all the changes at once.