Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

Git Tutorial

Git HOME Git Intro Git Install Git Config Git Get Started Git New Files Git Staging Git Commit Git Remove and Move Git Tagging Git Stash Git History Git Diff Git Blame Git Help Git Branch Git Merge Git Workflow Git Best Practices

Git and GitHub

GitHub Get Started Git What is SSH? GitHub Add SSH GitHub Set Remote GitHub Edit Code Pull from GitHub Push to GitHub GitHub Branch Pull Branch from GitHub Push Branch to GitHub GitHub Flow GitHub Pages Git GUI Clients

Git Contribute

GitHub Fork Git Clone from GitHub GitHub Send Pull Request

Git Undo

Git Revert Git Reset Git Clean Git Amend Git Rebase Git Reflog Git Recovery

Git Advanced

Git .gitignore Git .gitattributes Git Large File Storage (LFS) Git Signing Commits/Tags Git Cherrypick & Patch Git Bisect Git Merge Conflicts Git CI/CD Git Hooks Git Submodules Git Worktree Git Remote Advanced

Git and Bitbucket

Bitbucket Get Started Bitbucket Add SSH Bitbucket Set Remote Bitbucket Edit Code Bitbucket Branch Bitbucket Pages Bitbucket Fork Git Clone from Bitbucket Bitbucket Send Pull Request

Git and GitLab

GitLab Get Started GitLab Add SSH GitLab Set Remote GitLab Edit Code GitLab Branch GitLab Pages GitLab Fork Git Clone from GitLab GitLab Send Pull Request

Git Cert

Git Certificate

Git Reference

Git Glossary

Git Exercises

Git Exercises Git Challenges Git Quiz Git Syllabus Git Study Plan

Git Remove and Move


Share

Why git rm and git mv?

You can delete or rename files with your normal tools, but then you have to stage the change yourself.

git rm and git mv do both in one step: they change the file and stage the change for the next commit.


Remove a File (git rm)

Example: Delete a File

git rm notes.txt
rm 'notes.txt'
git status --short
D  notes.txt
Try it Yourself »

The file is deleted from your folder, and the deletion is staged. Commit it like any other change:

Example: Commit the Deletion

git commit -m "Remove old notes"
[main 29b1760] Remove old notes
 1 file changed, 1 deletion(-)
 delete mode 100644 notes.txt
Try it Yourself »


Stop Tracking a File, But Keep It (--cached)

Use --cached to remove a file from Git but keep it in your folder. This is useful when you committed a file by mistake, like a log or a file with passwords:

Example: Untrack a File

git rm --cached notes.txt
rm 'notes.txt'
git status --short
D  notes.txt
?? notes.txt
ls
index.html  notes.txt  style.css
Try it Yourself »

Add the file to .gitignore too, so it is not added again by mistake.


Remove a Folder (-r)

Use -r (recursive) to remove a folder and everything in it:

Example: Remove a Folder

git rm -r old-pages
rm 'old-pages/about.html'
rm 'old-pages/contact.html'
Try it Yourself »

Rename or Move a File (git mv)

git mv renames or moves a file, and stages the change:

Example: Rename a File

git mv style.css main.css
git status --short
R  style.css -> main.css
Try it Yourself »

Example: Move a File into a Folder

git mv style.css css/style.css
git status --short
R  style.css -> css/style.css
Try it Yourself »

Git keeps the history of a moved file. Use git log --follow to see the commits from before the move:

Example: History of a Moved File

git log --follow --oneline css/style.css
5cabbc0 (HEAD -> main) Move style.css into css folder
ebcff72 Style paragraphs
87e4062 First version
Try it Yourself »



Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.