2

The question is pretty self evident, I think, but still ...

my understanding of git mv (for the purposes of renaming) is that it renames the file, adds the new file to the branch, and removes the old file from the branch.

Wouldn't running mv by itself followed by git add -A serve the same purpose? It seems to me this second option would be preferable in many cases because the user will often run git add -A anyway.

macsplean
  • 611
  • 3
  • 8
  • 22
  • 2
    Probably yes, but `git mv` is shorter and more intuitive, so I prefer it. – Basile Starynkevitch Nov 01 '13 at 00:44
  • 1
    It appears so. This answer to this [question](http://stackoverflow.com/questions/1094269/whats-the-purpose-of-git-mv) suggests that `git mv` provides the same functionality as `git add -A`. That is Git for you, often many different ways to achieve the same thing! – miqh Nov 01 '13 at 01:26
  • 1
    `mv` is more familiar/intuitive to those of us coming from a Unixy background. – Edward Nov 01 '13 at 02:29
  • check this out - http://stackoverflow.com/a/1094392/1060656 – aked Nov 01 '13 at 03:52

1 Answers1

3

Well, you're right that a git mv is just a git rm of the old path and a git add of the new path. Obviously, though, git add -A stages everything in your working directory.

So, if you have only the unstaged rename, they would have the same effect. But if you have any other change in the working directory, those would also be staged by git add -A.

I don't think that git add -A is good practice, personally, and I don't think that most users will or should run git add -A. But if this is already a part or your workflow then no, you don't need to run git mv.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • Interesting. Firstly, thanks your response. Second, what do people generally do instead of `git add -A`? do people simply `git add` each change individually? Seems like much more work. – macsplean Nov 01 '13 at 05:23
  • @macsplean Indeed it is more work, but it also allows you to carefully choose which changes are included in a commit. I believe this makes it less likely to accidentally commit cruft, though that's just my opinion. Certainly the `git add -A` strategy has its advantages (simplicity, speed) and adherents. – Edward Thomson Nov 01 '13 at 13:00