I'm looking for a way to introduce changes into feature branches once they have been merged to master. The goal is to keep the feature branch keep only containing commits that are related to it.
It often happens that a feature needs some additional polishing after it has already been pushed to master. The changes that have been done to master during that time aren't in conflict with the feature, meaning that a rebase to actual master is possible when implementing the additional work on the feature branch.
The image below shows the situation:
Approach i used so far: Rebase to master and merge feature back to master
Against -> The feature branch is now poluted with parts from master.
Question: What are the approaches you take in practice to solve this issue?
Example code
To help describe the approaches below is the code to create the repo structure from the examples.
# mkdir test
git init
touch master-change-file
git add master-change-file
git commit -m "initial commit"
echo 1 > master-change-file
git commit -a -m "master commit 1"
echo 2 > master-change-file
git commit -a -m "master commit 2"
git checkout -b feature
echo 3 > feature-change-file
git add feature-change-file
git commit -a -m "feature commit 1"
echo 4 > feature-change-file
git commit -a -m "feature commit 2"
echo 5 > feature-change-file
git commit -a -m "feature commit 3"
git checkout master
git merge --no-ff feature -m "Merge branch 'feature'"
git checkout feature
echo 6 > feature-change-file
git commit -a -m "feature commit 4"
echo 7 > feature-change-file
git commit -a -m "feature commit 5"
git checkout master
echo 8 > master-change-file
git commit -a -m "master commit 3"
echo 9 > master-change-file
git commit -a -m "master commit 3"
# gitk --all
push
. From the context I would guess its afast forward merge
? – Bogy