Is it better to use git branch -f or git update-ref to fast-forward existing branch?
Asked Answered
R

1

2

I have realized that I can use git update-ref to fast-forward existing branch that I am not on. Then I have found that similar thing can be done by git branch -f. I understand that git update-ref is much more flexible (it can move any ref), however it could be dangerous. So is it better to use git branch -f? Are there any differences in these two commands in this particular scenarios? (Except of that I can specify custom ref log message.)

Representation answered 5/11, 2014 at 8:25 Comment(1)
FYI: Even with update-ref there is no real danger of losing commits, as described in the answer you linked to. The commits will be still there and you can stil easily recover them.Embellishment
A
3

With git branch -f, it would refuse to update the branch if it is the one checked out (so if it is the "current branch")

git update-ref has not that limitation.


Qqwy adds another difference in the comments:

  • git branch -f <branchname> [<start-point>] will create a new branch called <branchname> if it did not exist.
  • git update-ref <branchname> <newvalue> will do nothing in this case.
Aronoff answered 5/11, 2014 at 8:28 Comment(3)
It seems like update-ref doesn't provide the same autocomplete features branch -f does. Is it possible to change git's behaviour to create the same experience for update-ref?Embellishment
@Zeeker that would be a good separate question: I haven't look too much in the autocompletion part of those commands.Aronoff
I've asked another question.Embellishment

© 2022 - 2024 — McMap. All rights reserved.