How to rename a tracked file?

git mv old_name new_name

To rename a file tracked by git use git mv old_name new_name. This command will rename the file and add it to your staging area. You will still need to commit the changes with git commit.

Layer 1
Terminal Example
git mv image.png icon.png

git status
On branch main
Changes to be committed:
  (use "git restore --staged ..." to unstage)
    renamed:    image.png -> icon.png

See git mv to learn more about it.

Last modified on November 30, 2021.

You might also like