Git shortcut for moving tracked resources

Software

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.

Author bio and support

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!