Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to Git!
You have completed Introduction to Git!
Preview
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.htmlfile 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
rmcommand, 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.htmlfile has been deleted, but it shows that in the "Changes not staged for commit" section. - We can make the deletion of
tin.htmlpart of a commit by using thegit rmsubcommand. -
git rmis set up to work much like the plainrmcommand, so it's much like taking our previous command and stickinggitin front of it:git rm tin.html - Let's run
git statusagain... - ...and we'll see the deletion of
tin.htmlis 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 statusagain... - ...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.htmlfile is still gone. - By the way, we didn't need to run
rm tin.htmlas a separate step.git rmwill 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 upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Previously, we've shown you how to set up
a Git repository and commit files to it.
0:00
But with just the commands you know now,
when you commit a file,
0:00
well you're committed.
0:03
If you decide you need to delete or
0:05
move a file,
you can do it in your working directory.
0:07
But you can't do it in the Git repo.
0:09
If you staged the wrong file,
we haven't shown you how to unstage it.
0:12
In these next few videos,
we'll fix all that and more.
0:16
We'll show you how to delete or
0:20
move files in the get repo as
well as your working directory.
0:21
You'll learn how to unstage files
that you've accidentally staged.
0:25
We'll help you reset a file's
contents back to the way they looked
0:28
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