TIL how to rename/move folders in git projects

1 minute read Published:

Today I had the case that I wanted to rename a subfolder in a git-project at work. “Easy” I thought. Just rename the file in finder, stage all un-staged changes in SourceTree, commit and push.

But… the only thing that happened was that SourceTree complained about not being able to find files in the old foldername. So I googled a bit and found a solution.

How to really do it

Just use git mv on the shell! The syntax is git mv {source} {dest}

git mv sourcefolder/ destinationfolder/
git commit -m "renamed sourcefolder to destinationfolder"
[master 786609a] bla
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename {sourcefolder => destinationfolder}/examplefile.txt (100%)

So as we see… It’s still easy to move folders in git-repositories but not trivial because we have to use the shell.