Open In App

Git - Rename

Last Updated : 04 Oct, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Renaming files in Git is an important part of managing your project's structure and organization. The git mv command is used to rename or move files and directories within a Git repository efficiently.

We'll discuss both approaches.

  1. Using GitHub (Same applies to GitHub Desktop)
  2. Using the Command Line (terminal/ Power Shell)

Way 1: Rename using GitHub 

Step 1: Open GitHub.

Step 2: Open the repository to rename any file in that repository.

Step 3: Open the file which we want to rename.

Step 4: Click the edit button and rename the file.

Step 5: After renaming the file, commit the changes.

Step 6: A file with the new name will be saved.

Way 2: Renaming using the Command Line

Step 1: Open Git Bash.

Step 2: Open the repository.

Step 3: Rename the file using the command:

git mv old_filename new_filename

Step 4: Use the "git status" command to check the changes.

Step 5: Commit the renamed file.

git commit -m "Renamed_file"

Step 6: Push the changes using "git push origin branch_name"

It is as shown in below pictorial aid.

Suggested Quiz
5 Questions

Which command is used to rename a file in Git using the terminal?

  • A

    git rename old new

  • B

    git mv old_filename new_filename

  • C

    git change old new

  • D

    git move file

Explanation:

git mv old_filename new_filename is the official Git command used for renaming or moving files/directories.

After renaming a file using git mv, what should be done next to finalize the change?

  • A

    Run git reset

  • B

    Edit .gitignore

  • C

    Commit the changes

  • D

    Use git clone

Explanation:

Renaming counts as a change, so it must be committed using git commit to reflect in the repository.

Which GitHub interface step is required when renaming through GitHub website?

  • A

    Cloning the repository first

  • B

    Clicking the edit button on the file

  • C

    Running git add command

  • D

    Pushing changes from terminal only

Explanation:

On GitHub, you open the file → click Edit → rename → commit changes.

Which command can be used to verify file rename status after using git mv?

  • A

    git log

  • B

    git status

  • C

    git branch

  • D

    git clean

Explanation:

git status displays pending changes including renamed/moved files before committing.

What is the final step after committing the renamed file if you want the changes reflected on remote GitHub?

  • A

    git push origin branch_name

  • B

    git pull

  • C

    git checkout

  • D

    git fetch

Explanation:

To update the remote repository, you must push the commit using
git push origin branch_name.

Quiz Completed Successfully
Your Score :   2/5
Accuracy :  0%
Login to View Explanation
1/5 1/5 < Previous Next >

Article Tags :

Explore