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
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 upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
We just created an HTML file for our
silver medals page, here in silver.txt.
0:00
With our work saved,
we can close our editor.
0:06
Let's click back in the console,
0:09
make sure that we're in our
repository directory, cd medals.
0:11
And let's save the file for
committing, git add silver.txt.
0:15
And then, we'll commit it,
git commit -m "Add silver medals".
0:20
Unfortunately, only now do we realize
that we needed that file name
0:30
to be saved with a .html extension,
not a .txt extension.
0:35
But we've already committed
the file under the wrong name.
0:40
How can we fix this?
0:42
Git offers the git move command
to let you move files around.
0:44
It's typed as git mv, but
the mv is pronounced as move.
0:48
Like git rm, the name and
syntax of the git mv command
0:54
is based on an important Unix command that
does the same thing, but outside of git.
0:58
After you type git mv, you need to provide
the name of the file you want to move,
1:03
silver.txt, and the name of the file
you want to move it to, silver.html.
1:08
Hit Enter to run the command.
1:12
There won't be any output.
1:16
As usual, that's a good thing.
1:17
It means the command worked.
1:19
If we run ls now,
we'll see that the silver.txt file
1:21
has been moved to silver.html
in our working directory.
1:25
Now, let's try running git status.
1:29
We'll see, renamed,
1:32
silver.txt to silver.html in
the changes to be committed section.
1:34
That means the file
renaming has been staged.
1:40
Now, we just need to commit the change,
1:43
git commit -m "Rename
silver.txt to silver.html".
1:45
Let's run git status again.
1:58
And we'll see there are no
uncommitted changes.
2:02
If we run ls, we'll see the file
is still named silver.html.
2:05
And when our git repository is cloned,
2:08
that's the file name that
will be in the clone as well.
2:11
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