git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] status: suggest a force push after a clean rebase

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 6, 2026, 07:08 UTC
Message-ID
<46f98796e7b07d93899f2c43c2699a82834e9778.1791270504.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2437.git.git.1791270504.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>

After rebasing pushed work onto a newer upstream without changing it, "git status" says the branch was rebased cleanly but gives no hint on how to publish it. A plain "git push" is rejected, so suggest a force push:

  Your branch and 'origin/topic' have diverged,
  and have 51 and 1 different commits each (rebased cleanly on 'upstream/main').
    (use "git push --force-with-lease" to publish your local commits)

The lease still stops the push if someone else updated the push branch since it was last fetched.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 remote.c                 | 7 +++++--
 t/t6040-tracking-info.sh | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/remote.c b/remote.c
index 89d142cc7e..af8d026073 100644
--- a/remote.c
+++ b/remote.c
@@ -2468,7 +2468,7 @@ static void format_branch_comparison(struct strbuf *sb,
 					_("  (use \"git pull\" to update your local branch)\n"));
 		}
 	} else {
-		if (same_changes)
+		if (same_changes) {
 			strbuf_addf(sb,
 				Q_("Your branch and '%s' have diverged,\n"
 				       "and have %d and %d different commit each "
@@ -2478,7 +2478,10 @@ static void format_branch_comparison(struct strbuf *sb,
 				       "(rebased cleanly on '%s').\n",
 				   ours + theirs),
 				branch_name, ours, theirs, upstream_name);
-		else if (upstream_name)
+			if (use_push_advice && advice_enabled(ADVICE_STATUS_HINTS))
+				strbuf_addstr(sb,
+					_("  (use \"git push --force-with-lease\" to publish your local commits)\n"));
+		} else if (upstream_name)
 			strbuf_addf(sb,
 				Q_("Your branch and '%s' have diverged,\n"
 				       "and have %d and %d different commit each "
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index 2ebc3573da..4074c6663a 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -802,6 +802,7 @@ test_expect_success 'status.compareBranches after a clean rebase of the push bra
 
 	Your branch and ${SQ}origin/feature19${SQ} have diverged,
 	and have 3 and 1 different commits each (rebased cleanly on ${SQ}origin/main${SQ}).
+	  (use "git push --force-with-lease" to publish your local commits)
 
 	nothing to commit, working tree clean
 	EOF
-- 
gitgitgadget
Previous: Harald Nordgren via GitGitGadgetNext: Harald Nordgren via GitGitGadget
Message 4 of 7 in “status, push: handle a push branch rebased onto a newer upstream”
  1. 0/6 status, push: handle a push branch rebased onto a newer upstreamHarald Nordgren via GitGitGadget, Oct 6, 2026
  2. 1/6 status: count push divergence outside the upstreamHarald Nordgren via GitGitGadget, Oct 6, 2026
  3. 2/6 status: say when the push branch was rebased cleanlyHarald Nordgren via GitGitGadget, Oct 6, 2026
  4. 3/6 status: suggest a force push after a clean rebaseHarald Nordgren via GitGitGadget, Oct 6, 2026
  5. 4/6 push: name the branch to pull from when it is not the upstreamHarald Nordgren via GitGitGadget, Oct 6, 2026
  6. 5/6 push: offer a force push after rewriting pushed commitsHarald Nordgren via GitGitGadget, Oct 6, 2026
  7. 6/6 push: suggest a force push after a clean rebaseHarald Nordgren via GitGitGadget, Oct 6, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.