Git Tips Slides
PageUp x2: previous · PageDown x2: next · Home: index

Merge PR base branch into current branch

scripts/git-merge-pr-base.sh

Git itself does not know "this branch was originally created from that branch". But GitHub, GitLab, and Codeberg know the base branch of the current PR/MR.

This script autodetects the hosting provider from the URL of the current branch remote, uses gh, glab, or berg to resolve that base branch, then pulls it into your current branch.

That is useful if you want to refresh your branch with the latest changes from the branch your PR targets, without typing main or another branch name.

This is especially handy if you work with a chain/train of branches, because the base branch is not always main.

By default it pulls the PR base branch into your current branch. Use --no-pull if you want to skip that step and merge the existing remote-tracking ref instead.