This question already has an answer here:
-
GIT: How can I prevent foxtrot merges in my 'master' branch?
3 answers
We recently got into a situation wherein we could not push the code and got error message indicating "Control Freak... FoxTrot Merge"
Basically, this is our source tree-
Branch - A (this is a child of origin/develop which was off origin/master)
Created Another branch B from A - Work on it
Created another branch from C
At some point after few commits, it won't let us push any commits to C
and complained about FoxTrot merge.
We checked that bitbucket (enterprise) had a hook which blocks this.
We bypassed this (Since we really had to push the changes) by creating another branch D.
We don't know how we landed in this situation.
How can we avoid this in future?
I'm going to close this as a duplicate, but the "duplicate" question itself just defines foxtrot merges without explaining why they happen.
They happen because git pull
means git fetch && git merge
and that second git merge
is a "foxtrot merge". It treats your work as the main branch, and someone else's work, done on master
after you started on your work, as a secondary, probably-not-master branch. The goal of the hook is to prevent people from working on master and using git pull
like this.
To avoid having this sort of thing happen, you can use this simple rule (perhaps a bit too simple but it works): never do any work on master yourself.
That is, after:
git clone <url>
cd <clone>
you begin work with:
git checkout -b feature/tall
to work on the new feature named tall
. You, Alice—well, that's probably not your actual name, but I have three people doing things in this example, so I've assigned you the name "A"–do all your work on your own feature/tall
, while Bob and Carol do all their work on their own feature branches, whatever their features' names are.
Then when your stuff is ready you do:
git checkout master && git fetch && git merge
or, if you like git pull
(I don't):
git checkout master && git pull
You're now ready to merge your feature:
git merge feature/tall
and when the merge is complete—after resolving any merge conflicts if necessary—you can push again:
git push
and your work appears as a non-"foxtrot merge". Once your work is successfully merged and pushed you can delete your feature-branch. Meanwhile Bob and Carol can keep working on their features, or, if they finished before you did, your merge merges atop their merges.