Git Stage

At its core, the git add command is responsible for staging changes—marking modifications, deletions, or additions to files in the working directory as candidates for the next commit. Let's delve into the fundamental ways to utilize this command.

1. Staging Specific Files:

The most basic use of git add involves specifying individual files to stage. This is ideal when you want to be selective about the changes to include in the next commit.

bash
git add filename.txt
2. Staging All Changes:

To stage all changes in the working directory, you can use the dot (.) as a wildcard, indicating all files and directories.

bash
git add .
3. Staging Changes Interactively:

For a more interactive approach, the -p or --patch option allows you to review each change and decide whether to stage it or not.

bash
git add -p
4. Staging Portion of a File:

With the --patch option, you can stage only specific portions of a file, enabling precision in selecting the changes to include.

bash
git add -p filename.txt
5. Staging New and Modified Files:

Combining the -u or --update option with git add stages both modified and untracked (new) files.

bash
git add -u
6. Staging Changes Excluding New Files:

Conversely, the -A or --all option stages all changes but omits new files. This is useful for excluding untracked files from the staging area.

bash
git add -A
7. Staging Files with a Specific Extension:

You can stage files with a specific extension using the following command, replacing .txt with your desired extension.

bash
git add *.txt
8. Staging Changes Without Committing:

To stage changes without immediately committing them, you can use git add followed by git commit.

bash
git add . git commit -m "Your commit message"