I created a fork of an open source repository on GitHub and have been working on my main branch. Over time I’ve made several commits (let’s call them A, B, C, D, and E) but I only want to submit some of these changes back to the original project.
Specifically, I need to create a pull request that includes only commits B and E while leaving out the others. The tricky part is that I want to make sure this won’t cause merge conflicts later when I pull updates from the upstream repository back into my fork.
What’s the best approach to handle this situation? Are there different methods I could use to accomplish this goal?
hey, just create a new branch for this. use git cherry-pick <commit-b-hash> and git cherry-pick <commit-e-hash> to grab those specific commits. then push the branch to your fork and open the pull request. should keep things tidy!
You’ve got a couple good options. Cherry-picking works well, but I’d create your feature branch from upstream main instead of your own main - saves you headaches later. Just run git checkout -b feature-branch upstream/main then cherry-pick what you need. You’ll be working with the latest upstream code that way. You could also try interactive rebase if these commits are recent. Make a new branch and use git rebase -i to grab only what you want. Gets tricky though if your commits depend on each other. I’d go with cherry-picking - it’s simpler and less likely to break things. Just test everything after you cherry-pick since commits can act weird when pulled out of context. And don’t touch your original branch until the PR gets merged.