Rename a file with git mv
Description: Rename readme.txt to README.md and commit the change.
Hint:
git mv old newrenames the file and stages the change.
Solution
Terminal output
$ git mv readme.txt README.md
$ git status -s
R readme.txt -> README.md
$ git commit -m "Rename readme to README.md"
[main 6b0ae04] Rename readme to README.md
1 file changed, 0 insertions(+), 0 deletions(-)
rename readme.txt => README.md (100%)
$ git log –oneline –follow — README.md
6b0ae04 (HEAD -> main) Rename readme to README.md
38fa585 Add readme
How it works
Rin the status means renamed.--followkeeps the history of the file after the rename.
Read Git rm and mv.
Learn more about the similar topics:
| Tutorials |
|---|
| Git Init |
| Git Status |
| Git Add |
| Git Commit |
| Git Log |
| Git Diff |
| Git Ignore (.gitignore) |