Git shortcut for moving tracked resources

Yes, I didn't know this until today, much like there's someone born every minute who hasn't seen The Flintstones. Previously to move a file, I would have done this:

$ mv ./original ./new
$ git rm ./original
$ git add ./new
$ git commit -m 'moved original to new'

As an aside, you can also do git rm to remove the file and tracking, or use -f to just do the latter. I'm old fashioned, and prefer my source control just track stuff, rather than manipulating stuff directly. Stuff being the operative word. But I digress.

Not to get all Malcolm Gladwell on you (and stuff), but turns out, there's a mv command instead:

$ git mv ./original ./new
$ git commit -m 'moved original to new'

This way, the files are also associated, and stuff.


This is one of about 5000 posts on Rubénerd. View the home page for the latest, or related posts also tagged with:

If you liked this post, feel free to buy me a coffee, leave me a comment on Twitter, or email me at Thanks :).