Open In App
Related Articles

What is Git Add?

Improve Article
Improve
Save Article
Save
Like Article
Like

Git is a Distributed version control system to track the changes in the source code. Git is free and open-source software. The staging area in Git is the preview of your next commit. When you create a git commit, Git automatically takes changes that are in the staging area and makes them a new commit. You can add and remove changes from the staging area.

How do you add files to your Staging Area?

For this, you have to use the command git add <filename>. This will add a specific file i.e., you choose from your working tree to the staging area. If you want to add all the files to the staging area then use git add. The dot(.) operator will take all the files and add them to the staging area.

git add . : Staged new and modified files without deleting.
git add -a : Staged all files to the staging area.
git add -u : Staged modified and deleted files.

Let’s say you create a new folder inside the Git folder named SetUp and inside this SetUp folder, you create two files file1.txt and file2.txt. Now after git init, if you run git status then it is shown in red color means these files are untracked i.e., these are not in the staging area. Now if you run git add . , so the entire files in the working tree are added in the staging area and now it is showing in green color means that it is tracked.

 

To remove the file from the staging area the command used is: 

git rm --cached file-name

Note: Note that this will not delete the file, this will only remove the file from the staging area.

Refer to the below image.

 

You can see in the above image, we remove file1.txt from the staging area.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 28 Sep, 2022
Like Article
Save Article
Previous
Next
Similar Reads