From: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Harald Nordgren <haraldnordgren@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH 3/6] status: suggest a force push after a clean rebase
Date: Tue, 06 Oct 2026 07:08:21 +0000 [thread overview]
Message-ID: <46f98796e7b07d93899f2c43c2699a82834e9778.1791270504.git.gitgitgadget@gmail.com> (raw)
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
next prev parent reply other threads:[~2026-10-06 7:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 7:08 [PATCH 0/6] status, push: handle a push branch rebased onto a newer upstream Harald Nordgren via GitGitGadget
2026-10-06 7:08 ` [PATCH 1/6] status: count push divergence outside the upstream Harald Nordgren via GitGitGadget
2026-10-06 7:08 ` [PATCH 2/6] status: say when the push branch was rebased cleanly Harald Nordgren via GitGitGadget
2026-10-06 7:08 ` Harald Nordgren via GitGitGadget [this message]
2026-10-06 7:08 ` [PATCH 4/6] push: name the branch to pull from when it is not the upstream Harald Nordgren via GitGitGadget
2026-10-06 7:08 ` [PATCH 5/6] push: offer a force push after rewriting pushed commits Harald Nordgren via GitGitGadget
2026-10-06 7:08 ` [PATCH 6/6] push: suggest a force push after a clean rebase Harald Nordgren via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46f98796e7b07d93899f2c43c2699a82834e9778.1791270504.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=haraldnordgren@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox