rebase-current-branch
Rebase the Current Branch
Update the active branch by replaying its commits on top of the latest default branch from its upstream remote. Use the repository's actual default branch, whether it is named main, master, or another branch.
Workflow
-
Inspect before changing anything. Run
git status --porcelain=v1 --branch --untracked-files=allandgit branch --show-current. Confirm the current branch is not the default branch and note any local changes. If the working tree has changes, stop and ask the user whether to commit, stash, or otherwise handle them. Do not stash automatically. -
Identify the upstream and default branch. Check
git remote -vandgit remote show <remote>(or the remote's symbolicHEAD) to determine the branch this repository treats as its default. Prefer the configured upstream for the current branch when available; otherwise useorigin. Do not assume thatmainexists or that a branch namedmasteris current. If the default branch cannot be identified unambiguously, ask the user. -
Fetch the latest default branch. Fetch only the identified remote and default branch, for example:
git fetch <remote> <default-branch>Verify the fetched remote-tracking ref exists before continuing.
-
Rebase the active branch. Tell the user which branch will be rebased onto which remote-tracking branch, then run: