I'm having a small team working on a single repository, I asked my each teammates to create there own branch and work on there branch, all of them cloned the repository and then they did the following command:
git checkout -b BitPankaj
BitPankaj
is illustration branch name, they started working on this branch and uploaded there work through
git branch --set-upstream origin BitPankaj
Now in my repository I can see that those branch appears and their commits are also visible:
and Branches:
Now each one of them where trying to create a pull request to review there code and merge to master branch. so they tried doing something like this:
But it throws an error of unrelated branches:
The following error(s) occurred saving this pull request: Unrelated branches
We people are learning to work on git, help me out with this.
This is because the BitPankaj
branch is an orphan branch.
That means the branch BitPankaj
didn’t created from master
branch (as you expected), but may use git checkout --orphan BitPankaj
instead. The branch structure looks like:
A---B---…---C master
D---…---E BitPankaj
You can double check in your local repo. Update/pull the branches and show logs as graph:
git checkout master
git pull origin master
git checkout BitPankaj
git pull BitPankaj
git log --oneline --decorate --graph --all
#Or you can use gitk --all if you installed git bash
In order to create pull request between BitPankaj
and master
, you should change BitPankaj
branch based from master
branch.
To change BitPankaj
based from the latest version (commit C
) of master
branch:
git rebase master BitPankaj
git push -f origin BitPankaj
Then the commit history will like:
A---B---…---C master
\
D---…---E BitPankaj
To changes BitPankaj
branch based from an old version (such as commit B
) of master
branch:
git rebase <commit id for B> BitPankaj
git push -f origin BitPankaj
Then the commit history will like:
A---B---…---C master
\
D---…---E BitPankaj
Then you can create pull request to merge BitPankaj
into master
branch on bitbucket successfully.
You should be able to use --allow-unrelated-histories to force the merge to happen.
You should be able to use it like:-
git pull origin branchname --allow-unrelated-histories
for extra info have a look at:-
Git Merge Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With