diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb
index 7aa5a528b2c0d461d2c133645d97900ca7c19f8a..4d3b280f91e1ea9af206983ad03aaff872411012 100644
--- a/Library/Homebrew/cmd/update-report.rb
+++ b/Library/Homebrew/cmd/update-report.rb
@@ -4,6 +4,13 @@ require "formulary"
 require "descriptions"
 
 module Homebrew
+  def update_preinstall_header
+    @header_already_printed ||= begin
+      ohai "Auto-updated Homebrew!" if ARGV.include?("--preinstall")
+      true
+    end
+  end
+
   def update_report
     install_core_tap_if_necessary
 
@@ -17,6 +24,7 @@ module Homebrew
     end
 
     if initial_revision != current_revision
+      update_preinstall_header
       puts "Updated Homebrew from #{shorten_revision(initial_revision)} to #{shorten_revision(current_revision)}."
       updated = true
     end
@@ -37,13 +45,14 @@ module Homebrew
     end
 
     unless updated_taps.empty?
+      update_preinstall_header
       puts "Updated #{updated_taps.size} tap#{plural(updated_taps.size)} " \
            "(#{updated_taps.join(", ")})."
       updated = true
     end
 
     if !updated
-      puts "Already up-to-date."
+      puts "Already up-to-date." unless ARGV.include?("--preinstall")
     elsif hub.empty?
       puts "No changes to formulae."
     else
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh
index a0c7cc7e7becd401185e2cb3dcc77bee323c6c71..a36b25fb018ce8faf43f0610ed90889fbab65c64 100644
--- a/Library/Homebrew/cmd/update.sh
+++ b/Library/Homebrew/cmd/update.sh
@@ -213,7 +213,14 @@ pull() {
 
   trap '' SIGINT
 
-  pop_stash_message
+  if [[ -n "$HOMEBREW_DEVELOPER" ]] &&
+     [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]]
+  then
+    git checkout "${QUIET_ARGS[@]}" "$INITIAL_BRANCH"
+    pop_stash
+  else
+    pop_stash_message
+  fi
 
   trap - SIGINT
 }
@@ -231,6 +238,7 @@ homebrew-update() {
       --debug) HOMEBREW_DEBUG=1;;
       --rebase) HOMEBREW_REBASE=1 ;;
       --simulate-from-current-branch) HOMEBREW_SIMULATE_FROM_CURRENT_BRANCH=1 ;;
+      --preinstall) HOMEBREW_UPDATE_PREINSTALL=1 ;;
       --*) ;;
       -*)
         [[ "$option" = *v* ]] && HOMEBREW_VERBOSE=1;
@@ -316,11 +324,21 @@ EOS
            --header "If-None-Match: \"$UPSTREAM_BRANCH_LOCAL_SHA\"" \
            "https://api.github.com/repos/$UPSTREAM_REPOSITORY/commits/$UPSTREAM_BRANCH")"
         [[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit
+      elif [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]]
+      then
+        # Don't try to do a `git fetch` that may take longer than expected.
+        exit
       fi
 
-      git fetch --force "${QUIET_ARGS[@]}" origin \
-        "refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" || \
-          odie "Fetching $DIR failed!"
+      if [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]]
+      then
+        git fetch --force "${QUIET_ARGS[@]}" origin \
+          "refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" 2>/dev/null
+      else
+        git fetch --force "${QUIET_ARGS[@]}" origin \
+          "refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" || \
+            odie "Fetching $DIR failed!"
+      fi
     ) &
   done
 
diff --git a/Library/brew.sh b/Library/brew.sh
index 7f9d141cf5f77119f1094a0850bc02cbf95b100b..96ee3bd915bfd4e5ebd919bf7eb9843f92e6fb74 100644
--- a/Library/brew.sh
+++ b/Library/brew.sh
@@ -230,6 +230,19 @@ then
     & disown
 fi
 
+update-preinstall() {
+  [[ -n "$HOMEBREW_AUTO_UPDATE" ]] || return
+  [[ -z "$HOMEBREW_NO_AUTO_UPDATE" ]] || return
+
+  if [[ "$HOMEBREW_COMMAND" = "install" || "$HOMEBREW_COMMAND" = "upgrade" ]]
+  then
+    # Hide shellcheck complaint:
+    # shellcheck source=/dev/null
+    source "$HOMEBREW_LIBRARY/Homebrew/cmd/update.sh"
+    homebrew-update --preinstall
+  fi
+}
+
 if [[ -n "$HOMEBREW_BASH_COMMAND" ]]
 then
   # source rather than executing directly to ensure the entire file is read into
@@ -240,9 +253,9 @@ then
   # Hide shellcheck complaint:
   # shellcheck source=/dev/null
   source "$HOMEBREW_BASH_COMMAND"
-  { "homebrew-$HOMEBREW_COMMAND" "$@"; exit $?; }
+  { update-preinstall; "homebrew-$HOMEBREW_COMMAND" "$@"; exit $?; }
 else
   # Unshift command back into argument list (unless argument list was empty).
   [[ "$HOMEBREW_ARG_COUNT" -gt 0 ]] && set -- "$HOMEBREW_COMMAND" "$@"
-  exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/brew.rb" "$@"
+  { update-preinstall; exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/brew.rb" "$@"; }
 fi