diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index 08062e15b5..9e2541434e 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -247,7 +247,13 @@ class Updater end if @initial_branch != @upstream_branch && !@initial_branch.empty? - safe_system "git", "checkout", "--force", "-B", @upstream_branch, "origin/#{@upstream_branch}", *@quiet_args + # Recreate and check out `#{upstream_branch}` if unable to fast-forward + # it to `origin/#{@upstream_branch}`. Otherwise, just check it out. + if system("git", "merge-base", "--is-ancestor", @upstream_branch, "origin/#{@upstream_branch}") + safe_system "git", "checkout", "--force", @upstream_branch, *@quiet_args + else + safe_system "git", "checkout", "--force", "-B", @upstream_branch, "origin/#{@upstream_branch}", *@quiet_args + end end @initial_revision = read_current_revision