Git Move Files (original) (raw)

Last Updated : 18 Mar, 2026

Git move is used to relocate files or directories within a repository while preserving their history.

Usage of git mv

When a file is renamed manually, Git treats it as a deletion and a new file addition instead of a rename, which can affect proper tracking of file history.

mv

Options in git mv

git mv provides options to control and customize file move or rename operations.

Rename Operation

To rename a file within a Git repository, use the git mv command, which updates the file name while preserving its version history.

git mv oldfilename newfilename

Let’s take the earlier example. This time, we rename the file using the git mv command:

git mv gfg1.py gfg2.py

Now, Git recognizes this as a rename operation instead of a delete and add. This will be reflected in the output of the git status command, where the file is shown as renamed.

mv2

Move operation

Files can be moved within a Git repository using the git mv command, which updates the file location while preserving its history.

git mv filename dir/filename

**Example:

git mv gfg.py code/gfg.py

Consider moving gfg.py to code/gfg.py using git mv, which updates the file location while preserving its history and is reflected in git status.

mv3

Handling Conflicts

When moving files, you might encounter conflicts, especially if other team members are working on the same files. Here are some tips to handle conflicts: