Renaming folder within a repo loses file history

Hi All

It’s my understanding that Git can handle moving files within a repository (eg by renaming a folder) without losing the commit history.

Unfortunately this does not appear to be the case with GitHub which does lose the history of every file within the renamed folder.

Is there any way to rename a parent folder (not the Repo folder) without losing history?

ps. The method I’ve been trying is using the ‘mv’ command in a shell

1 Like

Hi @abstractspoon,

Maybe you do not know that the file name, on git or any operating system, are the path of the file (for example: /folder/filename.txt the real name of this is not filename but the entire path of the file). When you rename a file you delete the previous file and create a new one with the same contents but with another name, so the previous file no longer exists. With this in mind you can think what git does: deletes a file and creates a new one in history because the files are not the same.

Hope this helps :slightly_smiling_face:  


Mark helpful posts with Accept as Solution to help other users locate important info. Don’t forget to give Kudos for great content!


Also, if you use ‘mv’ in the console but go to GitHub Desktop for the commit, you can clearly see that a ‘rename’ is not the same as ‘add + delete’


Git supports this with -follow, apparently GitHub does not.


So you could look at viewing your repo in some other tool that supports this, eg SourceTree or GitKraken.

You could also try gitk --follow file.txt or git log --follow file.txt as described in

1 Like

This is very unfortunate that github does not support this. The whole point  of git is to remember history, and renaming files and folders is quite common and git can handle it.

When you rename a file in github, it even tells you that you renamed the file, but it also chooses to loose the history.

In my experience, the best way to retain the history of renames is using the command line and doing git mv <file or folder> - git seems to notice the rename and retains the file history.

I have faced this issue “Renaming the folder without loosing history” these steps we need to do,

git mv oldfolder temp && git mv temp newfolder
git commit
git push

The intermediate temp folder is unnecessary, you can just use git mv oldfolder newfolder. Otherwise correct. :slightly_smiling_face: