Renaming and Moving Files with Git
Learn how to rename and move files in a Git repository using `git mv` to keep history and stage changes correctly. Renaming and Moving Files with Git When you rename or move files in a Git repository, using Git's built-in commands ensures the change is tracked properly and staged for commit. Using git mv The `git mv` command renames or moves a file and stages the change automatically: git mv old_filename new_filename This works for both renaming and moving files to different directories. Example: Rename a File git mv README.md README.txt git commit -m \\"Rename README.md to README.txt\\" Example: Move a File to a Subdirectory mkdir docs git mv README.txt docs/README.txt git commit -m \\"Move README.txt to docs directory\\" Alternative: Manual Rename/Move You can manually rename or move files using shell commands, but you must then stage the changes: mv old_...