Open In App
Related Articles

Git – Rename

Improve Article
Save Article
Like Article

Renaming the file is very important when we are working on a project. Git Rename is used to rename a file in the working directory. Suppose we are working in a team and any fellow developer created the file and we want to rename it using Git or Github so this command help us to do so. We may change the name of the file even though we created the file due to some reason. To rename any file or folder, use git mv command which takes two arguments. The first argument is the source and the second is the destination. We can easily rename any file using the git command and the new name will be assigned to that file. We can rename the file using GitHub or the command line. 

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.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Feb, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials