You should be able to rebase your branch on master:
git checkout feature1
git rebase master
Manage all conflicts that arise. When you get to the commits with the bugfixes (already in master), Git will say that there were no changes and that maybe they were already applied. You then continue the rebase (while skipping the commits already in master) with
git rebase --skip
If you perform a git log
on your feature branch, you'll see the bugfix commit appear only once, and in the master portion.
For a more detailed discussion, take a look at the Git book documentation on git rebase
(https://git-scm.com/docs/git-rebase) which cover this exact use case.
================ Edit for additional context ====================
This answer was provided specifically for the question asked by @theomega, taking his particular situation into account. Note this part:
I want to prevent [...] commits on my feature branch which have no relation to the feature implementation.
Rebasing his private branch on master is exactly what will yield that result. In contrast, merging master into his branch would precisely do what he specifically does not want to happen: adding a commit that is not related to the feature implementation he is working on via his branch.
To address the users that read the question title, skip over the actual content and context of the question, and then only read the top answer blindly assuming it will always apply to their (different) use case, allow me to elaborate:
git merge master
as in @Sven's answer).Finally, if you're unhappy with the fact that this answer is not the best fit for your situation even though it was for @theomega, adding a comment below won't be particularly helpful: I don't control which answer is selected, only @theomega does.