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.)
Asked
Active
Viewed 371 times
1

user2528260
- 115
- 1
- 5

TN.
- 18,874
- 30
- 99
- 157
-
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. – Sascha Wolf Nov 05 '14 at 12:38
1 Answers
2
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.
-
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`? – Sascha Wolf Nov 07 '14 at 08:57
-
@Zeeker that would be a good separate question: I haven't look too much in the autocompletion part of those commands. – VonC Nov 07 '14 at 09:27
-
I've asked [another question](http://stackoverflow.com/questions/26798130/expand-gits-autocomplete-feature-to-plumbing-commands). – Sascha Wolf Nov 07 '14 at 09:33