> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Undo Git Add and Remove Files from Staging
- URL: https://linuxhandbook.com/git-undo-add/
- Published: 2024-06-24T06:29:05.000Z
- Updated: 2024-06-24T06:29:05.000Z
- Description: Accidentally add a file that was not supposed to be added? If you have not made the commit yet, you can undo the git add and remove the file from staging.
- Author: Sagar Sharma
- Tags: Using Git, #docs-col

There are times when the files you added using the `git add` command were irrelevant and now you want to undo the git add. 

You can totally do that. Here are two ways to undo the git add changes:

1. Using the git reset command
2. Using the git rm command

For the explanation, I added two files using the git add command: Hello.txt and LHB.txt:

![](https://linuxhandbook.com/content/images/2024/02/stage-files-in-git.png)

Now, I'll show you how I'll remove them from the git add. Needless to say that you have not committed the changes yet.

## Undo git add using the git reset command

🚧

Avoid this method if it's a newly initialized Git project that has no commits yet.

The [git reset](https://git-scm.com/docs/git-reset?ref=linuxhandbook.com) is the easiest way to undo git add as it does not require any complex flags and all you have to do is append the file or path to the git reset command:

```
git reset <file/path>
```

For example, here, I want to unstage the `Hello.txt` and `LHB.txt` file so I will be using the following:

```
git reset Hello.txt LHB.txt
```

![Use the git reset command to undo git add in Linux](https://linuxhandbook.com/content/images/2024/02/Use-the-git-reset-command-to-undo-git-add-in-Linux.png)

Alternatively, you can also use wildcard to unstage multiple files having the same file extension:

```
git reset *filetype
```

Let's say I want to unstage every file ending with `.txt`, then I will use the following:

```
git reset *txt
```

![Undo git add using the git reset command through a wildcard for batch action](https://linuxhandbook.com/content/images/2024/02/Undo-git-add-using-the-git-reset-command-through-a-wildcard-for-batch-action.png)

💡

If you want to undo everything from git add, use `git reset .`

## Undo git add using the git rm command

If you don't like the idea of using the git reset command, then you can achieve the same behavior from the git rm command.

But unlike the previous command, here, you need to use one extra flag `--cached` with the git rm command:

```
git rm --cached <file/path>
```

Here, I used the wildcard to remove all the staged `.txt` files:

```
git rm --cached *.txt
```

![Use the git rm command to undo git add command](https://linuxhandbook.com/content/images/2024/02/Use-the-git-rm-command-to-undo-git-add-command.png)

Pretty easy. Right?

## More on Git 💻

I personally find Git one of the most critical skills to have if you are a computer student especially when it serves as a resume. 

So here's how to [create a jaw-dropping GitHub profile](https://linuxhandbook.com/github-profile-tips/) for students:

[7 Tips to Make a Rockstar Student Developer GitHub ProfileTime to enhance the look and feel of your boring default GitHub profile with these tips and suggestions.![](https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png)Linux HandbookPrakhar Tiwari![](https://linuxhandbook.com/content/images/2024/01/best-practices-for-rockstar-student-developer-profile.png)](https://linuxhandbook.com/github-profile-tips/)

Don't like GitHub? Here's a [list of top GitHub alternatives for self-hosting](https://itsfoss.com/github-alternatives/?ref=linuxhandbook.com) your opensource projects:

[Microsoft GitHub Alternatives to Host Your Open Source ProjectsIf you are looking to migrate from GitHub, here are some of the best alternatives to GitHub for hosting the source code of your open-source project.![](https://itsfoss.com/content/images/size/w256h256/2022/12/android-chrome-192x192.png)It's FOSSAbhishek Prakash![](https://itsfoss.com/content/images/wordpress/2022/11/top-github-alternatives.png)](https://itsfoss.com/github-alternatives/?ref=linuxhandbook.com)

I hope you will find this guide helpful.