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
Just as the "git rm" command lets you remove files from a repo, the "git mv" command lets you move (or rename) files within a repo.
- We just created an HTML file for our silver medals page, here in
silver.txt
. - Let's stage the file for committing:
git add silver.txt
- And then we'll commit it:
git commit -m "Add silver medals"
- Unfortunately, only now do we realize that we needed that file name to be saved with a
.html
extension, not a.txt
extension. - But we've already committed the file under the wrong name! How can we fix this?
The git mv
command
- Git offers the
git mv
command to let you move files around. - After you type
git mv
, you need to provide the name of the file you want to move,silver.txt
, and the file name you want to move it to,silver.html
.
git mv silver.txt silver.html
- If we run
ls
now, we'll see that thesilver.txt
file has been moved tosilver.html
in our working directory. - Now let's try running
git status
... - We'll see "renamed: silver.txt -> silver.html" in the "Changes to be committed" section.
- That means the file renaming has been staged.
- Now we just need to commit the change:
git commit -m "Rename silver.txt to silver.html"
$ git mv silver.txt silver.html
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: silver.txt -> silver.html
#
$ git commit -m "Rename silver.txt to silver.html"
[master 9505066] Rename silver.txt to silver.html
1 file changed, 0 insertions(+), 0 deletions(-)
rename silver.txt => silver.html (100%)
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
vamosrope14
14,932 Points1 Answer
-
Lisa Weil
4,919 Points1 Answer
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