Pull request behavior #150537
Replies: 1 comment
-
Hey bro! I totally get your frustration with GitHub's "Rebase and Merge" behavior. It can be a headache when it updates committer information and creates new commit SHAs. Why is this?I think GitHub enforces this approach to keep metadata consistent across projects. Unlike Possible Workarounds1. Rebase Locally and PushInstead of using GitHub’s UI, you can do the rebase manually: git checkout feature-branch
git rebase main
git push --force-with-lease 2. Use Fast-Forward MergesIf your project setup allows it, you can use a fast-forward merge to keep history clean: git checkout main
git merge --ff-only feature-branch 3. Squash and MergeNot the best for keeping detailed commit history, but if your team is okay with it, "Squash and Merge" combines all commits into one. This might be useful if you're mainly concerned about tracking feature implementations rather than individual changes. 4. GitHub ActionsYou could also set up a GitHub Action to handle rebasing automatically before merging: name: Auto Rebase
on:
pull_request_target:
types: [opened, synchronize]
jobs:
rebase:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Rebase and Push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin main
git rebase origin/main
git push --force-with-lease This way, your PRs always stay in sync without having to manually rebase them. |
Beta Was this translation helpful? Give feedback.
-
Has anyone found a workaround to this:
"The rebase and merge behavior on GitHub deviates slightly from git rebase. Rebase and merge on GitHub will always update the committer information and create new commit SHAs, whereas git rebase outside of GitHub does not change the committer information when the rebase happens on top of an ancestor commit. For more information about git rebase, see git-rebase in the Git documentation."
In my last project, this behaviour is a deal breaker for us, as it breaks all the auto-generated tags for canary releases and breaks other links.
Any solution apart from doing it via
git
and avoiding pull requests?Do you have any idea why this behavior?
Edit:
To add more context. The issue we are facing is that commits are recreated even when the brench being rebased is a direct anchestor of the default branch.
Beta Was this translation helpful? Give feedback.
All reactions