This blog will illustrate the procedure to rename a directory in a Git repository.
How to Rename a Git Directory in a Repository?
To rename a directory, first, view all the Git directories by executing the “ls” command. Then, choose the directory you want to rename and utilize the “$ git mv <source-directory-name> < new-directory-name>” command.
For this purpose, look at the provided instructions.
Step 1: Open Git Bash Terminal
First, launch the “Git Bash” command line terminal from the Startup menu:
Step 2: Go to Git Repository
Next, go to the required Git repository:
Step 3: View All Files and Directories
View all files and directories of the Git repository through the provided command:
Alternatively, the user can utilize the “git ls-file” command to view the directories file in detail:
Step 4: Rename Directory
Now, rename the Git directory by utilizing the “git mv” command. Also, specify the old directory name and new directory name along with the command:
Using the above command, we will rename the “test” directory as “features”:
Again, view all files and directories of the repository to verify if the directory is renamed or not:
You can see that we have successfully renamed the directory:
Step 5: Add Changes to Staging Area
Move the untracked changes to the tracking index (staging area) by executing the mentioned command:
Check out the repository state to verify if the changes are added to the staging environment or not:
You can see the directory renamed changes are added to the staging index:
Step 6: Commit the Changes
Next, commit the tracked changes using the “git commit” command. This will properly save the directory in the local repository with the new name:
Check the repository logs to verify if the changes or committed or not:
It can be observed that the changes are committed successfully:
We have taught you the procedure to properly rename the Git directory in a Git repository.
Conclusion
To rename the Git directory in a Git repository, first, open the repository and choose the directory you want to rename. After that, utilize the “git mv <source-dir-name> <new-dir-name>” command to rename the directory. Now, add the untracked changes to the tracking index and then, commit these changes using the “git commit” command. This write-up has demonstrated the method for renaming Git directories in the Git repository.