Git Move
The git mv command is used to move or rename files within a Git repository. It’s a more convenient way to move or rename files compared to manually deleting and adding files. This command also helps in tracking the history of file movements and naming alterations.
Syntax
git mv <old-file-path> <new-file-path>
Use Cases
1. Moving a File
To move a file from one location to another, use the git mv command like this:
git mv source_filepath destination_filepath
This will move the file.txt from the source directory to the destination directory.
2. Renaming a File
To rename a file, simply use the git mv command with the old and new file names:
git mv old-name.txt new-name.txt
This renames old-name.txt to new-name.txt.
It is essential to commit the changes after using
git mvto ensure that the file moves and renames are properly tracked in the Git history.Renaming or moving files with
git mvpreserves the file’s history and is especially useful in collaborative development to maintain a clear and organized project structure.The
git mvcommand can also be used with wildcards or regular expressions to move or rename multiple files simultaneously.
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Git on Codecademy
- Use our beginner friendly Git course to integrate Git and GitHub and manage versions of your projects using Git branches.
- With Certificate
- Beginner Friendly.4 hours
- Learn about the command line, starting with navigating and manipulating the file system, and ending with redirection and configuring the environment.
- With Certificate
- Beginner Friendly.4 hours