Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Removing Files 4:14
- Removing Files 3 objectives
- Moving Files 2:14
- Moving Files 3 objectives
- Unstaging Changes 1:51
- Unstaging Files 2 objectives
- Discarding File Modifications 2:59
- Discarding File Changes 2 objectives
- Undoing File Deletions 1:18
- Recovering Deleted Files 3 objectives
- Commit SHAs and Undoing Commits 5:06
- Undoing Commits 2 objectives

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Removing a file from your working directory is not the same as removing it from your Git repo. In this video, we'll learn about the "git rm" command.
Removing a file from the working directory
tin.html
:
<h1>Check out our tin medals!</h1>
<p>Medallion: $10</p>
<p>Ribbon: $50</p>
- We've added a
tin.html
file showcasing the store's new tin medals. - If we run
git status
, we'll see the file is untracked. - So let's add it:
git add tin.html
- And then we'll commit it:
git commit -m "Add tin medals"
- But suppose we later learned that customers weren't too pleased with the new tin medals, and we've decided to drop the product.
- We can delete the file from our terminal using the
rm
command, which stands for "remove":rm tin.html
Removing a file from Git
- If we run
git status
, it still shows the deleted file:
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: tin.html
#
no changes added to commit (use "git add" and/or "git commit -a")
- It shows that the
tin.html
file has been deleted, but it shows that in the "Changes not staged for commit" section. - We can make the deletion of
tin.html
part of a commit by using thegit rm
subcommand. -
git rm
is set up to work much like the plainrm
command, so it's much like taking our previous command and stickinggit
in front of it:git rm tin.html
- Let's run
git status
again... - ...and we'll see the deletion of
tin.html
is listed in the "Changes to be committed" section now.
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: tin.html
#
- Next, we can commit as usual:
git commit -m "Remove tin medals"
- Now we can run
git status
again... - ...and this time it will show the working directory is clean.
$ git status
# On branch master
nothing to commit, working directory clean
- And if we run
ls
, we'll see that thetin.html
file is still gone. - By the way, we didn't need to run
rm tin.html
as a separate step.git rm
will remove the file from the working directory for you, if it exists.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
hsuan29 Chen
1,740 PointsWhy can't I see the "console" has existed "/workspace/medals"?
Posted by hsuan29 Chenhsuan29 Chen
1,740 Points0 Answers
-
emmanuelsantana
2,415 Points1 Answer
-
Chantal Baxter
Front End Web Development Techdegree Student 4,858 Points1 Answer
-
Natalia Cielinski
14,115 Points1 Answer
-
James Phelps
8,262 Pointsgit repo not working "fatal: bad object HEAD" - seen as a rare issue
Posted by James PhelpsJames Phelps
8,262 Points1 Answer
-
polentz
Full Stack JavaScript Techdegree Student 11,755 Points1 Answer
-
chazber
4,873 Points1 Answer
-
vamosrope14
14,932 Points2 Answers
-
Jamie Reardon
Treehouse Project Reviewer1 Answer
-
Angella McCoy
3,231 Points1 Answer
-
Axel Perossa
13,930 Points1 Answer
-
marekdzicio
6,429 Points3 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up