Why would a simple `git mv` fail?

I am trying to rename a file in a local .git directory:

git mv MyProj/src/ts0621/foobar.c NewProjName/src/ts0629/foobar.c

Yet, git fails with:

  • Checking if a Git branch has been merged into master when SQUASHED?
  • How to put Git repository inside another repository?
  • Why isn't .gitignore ignoring .sass-cache?
  • How to conclude your merge of a file?
  • Best (and safest) way to merge a git branch into master
  • How can I change the remote/target repository URL on Windows?
  • fatal: renaming 'MyProj/src/ts0621/foobar.c' failed: No such file or directory

    I could swear that I had git mv working for me when renaming a subdirectory, but for some reason a simple rename of a file doesn’t work. Why?

    (I, of course, verified that the file MyProj/src/ts0621/foobar.c exists before attempting to issue this command)

  • Bzr fast-export return bzr: broken pipe
  • Git signoff commit without changing author
  • Forge + Git + Laravel issue
  • ERROR virtualenvwrapper in GitBash
  • Eclipse and external src and web content folder linking or mapping
  • How do I rename the .git directory?
  • 2 Solutions collect form web for “Why would a simple `git mv` fail?”

    Probably, because NewProjName/src/ts0629 doesn’t exist


    mkdir -pv NewProjName/src/ts0629
    git add NewProjName/src/ts0629

    add -f , if the path is relative, to increase git mv -f "originPath" "newPath"

    git mv -f MyProj/src/ts0621/foobar.c NewProjName/src/ts0629/foobar.c
    Git Baby is a git and github fan, let's start git clone.