[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