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.