THE PROBLEM : Commits from a deleted integration branch exist in a feature branch. They need to be deleted or reverted.
DETAILED SOLUTION:
In the future, change your workflow as follows.
- Do not merge the integration branch into a feature branch.
git pull origin develop
- Do merge master into a feature branch.
git pull origin master
- Do merge a feature branch into the integration branch named develop.
git checkout develop && git merge my-feature
Details
The ff-only option ensures devs only get changes that are fast-forwardable and that their feature doesn't get polluted by transient mutations in the develop branch.
Developers should originate their feature-that-works branch from master.
At the start of work:
git pull
git checkout master
git checkout -b feature-that-works
Now I have a new branch named feature-that-works and I am ready to start coding my feature.
What happens if I pull the integration branch develop directly into my feature-that-works branch? My feature branch gets contaminated with every other work-in-progress that's merged into the integration branch. I don't have control of other work in progress and generally, I don't want it contaminating my clean feature branch. That is why I do not pull from the integration branch named develop into my feature-that-works.
Stay up to date with changes
It's not a problem to pull master into a feature branch. Sometimes I fetch from master several times per day in my continuous deployment project. This is fine!
git checkout feature-that-works
git pull --ff-only origin master
The command above with the --ff-only option will fail if there are conflicts.
What to do when there are conflicts
This next command rebases master under feature-that-works.
git pull -r origin master
When the ff-only option fails due to conflicts, I must rebase my branch on top of master. Another way to say this is that I need to rebase master under my feature branch. This ensures that the master branch can always be fast-forwarded.
By rebasing in my local feature branch it will be possible to replay the commit history from my feature branch onto the master branch without any merge conflicts. I am resolving all conflicts locally, rather than waiting until it's time to apply my changes onto the master branch. If there's a problem, hopefully it's a small one that I can resolve locally, instead of waiting and making it someone else's bigger headache downstream.
Here's another good explanation with a simple visual describing why ff-only is preferred to git merge.
An interesting fact: without the ff-only option the git pull command is actually the same as git fetch + git merge.
Integration
I merge a feature-that-works into develop. As I mentioned before, it does not work the other way around.
git push origin feature-that-works
git fetch
git checkout develop
git reset --hard origin/develop
git pull origin feature-that-works
git push origin develop
The reason I used git reset --hard origin/develop is because the develop branch is mutable. Develop can be force pushed by someone else. I want to make sure that my local develop branch matches the remote upstream branch origin/develop.
That's just about it. Keep in mind that even with good workflow, developers need to communicate and may occasionally have to resolve merge conflicts together with other devs.
developinto hisfeaturebranch and resolve conflicts in there. After, it should be good to merge intodevelopgit rebase --onto <newparent> <oldparent>, where<newparent>isdevelopbranch, and<oldparent>is the parent of a very first commit in thefeaturebranch.developand rarely intomaster? Or is it common for them to ff merge intomastersometimes too? (i.e. What is the reasonmastersometimes diverges fromdevelop?)Masteris your true base/trunk branch. Please see my detailed answer below. Thanks!