| by Arround The Web | No comments

git-stage Command in Git | Explained

In Git, staging is the step that enables users to continue making modifications to the Git working directory. Moreover, when they need to interact with the version control, it enables them to record changes in commits for later use. These record changes can be displayed by utilizing the “git status” command.

This blog will discuss:

What is Staging in Git?

Before committing changes to the Git repository, users must tell Git what files they need to commit, such as newly created untracked files, or modified or removed files. This is known as staging. Moreover, users are allowed to add single as well as multiple files at once.

Syntax

The general syntax for adding a single file to the Git staging index is provided below:

git add <file_name>

Here, the “<file_name” will be replaced with the desired untracked file name.

The general syntax for adding all untracked files at once is as follows:

git add .

How to Stage a Single File in Git?

To stage a single file in Git, follow the provided steps:

  • Move to the Git local repository.
  • Generate a new file.
  • Track changes to the Git staging index.
  • Check the current status for verification.

Step 1: Navigate to Local Repository

Initially, use the below-stated command and go to the Git local repository:

cd "C:\Users\nazma\Git\Demo13"

Step 2: Generate Text File

To generate a new file, use the “touch” command:

touch file2.txt

Step 3: Stage Changes

Move the file from the Git working area to the staging index, and run the “git add” command with the file name:

git add file2.txt

Step 4: Verification

Lastly, use the “git status” command and check the current state of the new file:

git status

As you can see, the “file2.txt” has been tracked successfully:

How to Stage All Files in Git?

Check out the provided instructions to stage all untracked files in Git:

  • Create multiple new files.
  • Execute the “git add .” command.
  • Check the tracked file’s current status.

Step 1: Generate Multiple Files

Use the “touch” command along with the files name and generate them:

touch file3.txt file4.txt

Step 2: Tracked All Files

Now, run the “git add .” command and move all untracked files into the staging index:

git add .

Step 3: Check Files Current State

To view the multiple added file’s current states, use the provided command:

git status

As you can see, the below-highlighted files have been staged successfully:

That’s all! We have provided the ways to stage changes in Git.

Conclusion

The staging is known as before saving the changes in the Git repository, users must tell Git what files they need to commit, such as newly created untracked files, and modified or removed files. Users can add single or multiple files at once. The “git add <file_name>” command is used for tracking a single file and the “git add .” command is used for staging multiple files simultaneously in the Git staging index. This post illustrated the methods of stage changes in Git.

Share Button

Source: linuxhint.com

Leave a Reply