Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding merge commits in pull requests in git

Tags:

git

github

So, I want to create a pull request that only includes the changes to file1, file2, and file3 (i.e. updates for a feature).

The workflow I used:

git clone https://github.com/eghm/project.git project-eghm-clean
cd project-eghm-clean
git remote add upstream https://github.com/forkeduser/project.git
git fetch upstream
git merge upstream/master
git push
git branch featurebranch
git checkout featurebranch
#edit files: file1, file2, file3
git add file1
git add file2
git add file3
git commit -m 'updates for feature'
git push --set-upstream origin featurebranch

Then on github I went to my forked repository, selected Branch: featurebranch, and clicked Pull request. The request includes my merges from synching my fork:

pull request includes sync merges

How can I avoid this in the future?

like image 778
EGHM Avatar asked Feb 09 '23 10:02

EGHM


1 Answers

You should just git rebase against the branch that you're issuing your pull request against. For instance:

git rebase origin/master

Since this will change the history of your branch, you are better off doing this rebase in a new branch. So:

git checkout -b new_rebased_branch
git rebase origin/master

For future reference, if you don't want merge commits in your pull requests, you should try to update your branches via rebase rather than merge. Again, I always recommend checking out a separate branch to do this in, since rebasing will change your commit history, you may want to keep a backup of the original commit history.

like image 105
mkrufky Avatar answered Feb 13 '23 04:02

mkrufky