How to rename files so that git can detect it.
Tags: javascript, git, webdev, codenewbie
Published: 2022-01-29 16:32:00


Renaming files on **git** can be really painful to deal with. Git is case insensitive, so we can’t rename the file and hope for them to be updated in the **remote repository**. It can also create all sorts of  **problems** for yourself and your team.
Today, I will point down a step by step process to solve this particular problem.

**Problem:**
Let’s discuss what happen when you manually tried to rename `Containers` to `container`. Also, keep a close eye on the git lens change in sidebar.

![Before manually renaming](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iyri53zdomxr60aq8km9.png)

![After manually renaming](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiz8fzp4iivm3wji4o4a.png)

> We tried to manually change the files name from `uppercase` to `lowercase` which git  wasn’t able to detect. Let's see if our remote repository also has the same naming conversion problem after we push the code.

![remote repository after renaming manually](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wtj8d8a26mmphuyqws3.png)

> It seems the `git` wasn't able to detect the case-sensitive.

Let’s see how we can solve the problem and make `git` detect our file changes.

**Solution:**
There could be multiple way we could solve case-sensitive problem and we would use two different ways to solve the problem. Let's move on to our first solution.

1. **Using git-mv command:**

``` 
git mv <your_file_name><temporary_file_name>
git mv <temporary_file_name><new_file_name> 
```

- Let's make sure we have navigated to file location before using above command.

![using git-mv command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2mdy20gf2o6wrr7e7gk.png)

> The above command will delete the file or folder and add a new one with the same content. You can achieve the same facility by deleting the file and adding a new one with the same content. `Git` facilitates the process as you don't need to manually delete a file. 

- It will work on both folder and files cases.

Let’s use the same command on other remaining files as well.


![renaming Logo.png to logo.png file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2yj0i8x155b3oeftlrk0.png)

> `Logo.svg to logo.svg`

![renaming App.js file to app.js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytjht6l96cwdzrcpmawo.png)

> `App.js to app.js`

After renaming the above files, we should commit and push the changes to the remote repository.

**Result:**

![remote repository after git mv command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4pdrbgq8mfkqj9dyucy.png)

> We finally made the changes on the remote repository as well. And it worked!

2.**Second Method:**

This method will be a little different than the previous one. We are going to **manually** change the name but we have to add an extra symbol or letter to it. Don’t worry, I will explain it more so that you can understand how it works. 

Let’s break down the process into two different steps:

**A**. In the first step, we are going to rename `Containers` to `containers-1`. I have renamed it `containers-1`, so that I will have zero confusion in the next step. Although you can rename with whatever you want, I will suggest a name with more readability.

![renaming App.js to app.js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5y8tz7xkceuneoo21p51.png)

> As we could see above, `git` will detect the changes as a given folder `Containers` was deleted and another new folder `containers-1` is added but reality is we only changed the name of the folder.

Let’s make the changes to other files as well `App.js` to `app-1.js` and `Logo.svg` to `logo-1.svg`

![renaming all file manually](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ia9i93s8q49o9oat5hh.png)

Before moving to the next step, we should commit our changes so that our changes are save in our local device.
  

```
 git add .
 git commit -m “temporary name change”
```

![committing the changes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9ql332qenqhtrob32d2.png)

**B**. In this step, we will follow the same exact process but this time we rename the file  to the exact name which we want. In our case, it will be  `containers-1` to  `containers`. Let’s make the changes with other files as well `app-1.js` to `app.js`, `logo-1.svg` to `logo.svg`.

![rename the remaining files](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ktmiieczz91bja2zsu17.png)

> After you change the name, we have to  commit the changes and push it to remote repository.

```
git add .
git commit -m “Manually changing name”
git push origin master.
```

![committing manually changed file name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5kj9xd1dn85euoxcvew8.png)

**Result:**

![Containers to container](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4vpdgyah7oh5eu3knqm.png)
> We successfully changed our files and folder names in our local system as well as remotely. It worked!

>  `Containers to containers`

![App to app.js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/folayhnmlk0ej73kq70p.png)

> `App.js to app.js`


![Logo.png to logo.svg](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h25ai6i7dpiit5zdxnxj.png)

> `Logo.svg to logo.svg`

**To summarize**, both methods are effective and work with all scenarios.
You can use any method as you prefer. And if you have a different approach which can solve this problem much easier than please do feel free to share it.