Skip to content

Instantly share code, notes, and snippets.

@Magnus167
Last active February 26, 2024 01:17
Show Gist options
  • Save Magnus167/c593f9c36c5a6397d7561d530a058124 to your computer and use it in GitHub Desktop.
Save Magnus167/c593f9c36c5a6397d7561d530a058124 to your computer and use it in GitHub Desktop.
git pmerge - pull & merge. Use with Windows (powershell) or Unix-like alike
# Usage:
# git checkout featureX
# git pmerge main
# When merging branch `main` into `featureX`,
# one often has to pull from `main` to ensure
# merging into the correct head.
# Assume you're on branch featureX
# >> git pmerge main
# executes:
# >> BRANCH=$(git branch --show-current) # BRANCH is featureX
# >> git checkout main
# >> git pull
# >> git checkout BRANCH
# >> git merge main
git config --global alias.pmerge '!f() { BRANCH=$(git branch --show-current); git checkout "$1" && git pull && git checkout "$BRANCH" && git merge "$1"; }; f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment