Your branch is no longer directly based off of the branch you're trying to merge it into - e.g. another commit was added to the destination branch that isn't in your branch. Thus, you can't fast-forward into it (because fast-forward requires your branch to completely contain the destination branch).
The alternative (and longer) way of fixing the fatal: refusing to merge unrelated histories issues is to unstage your current commits, stash them, clone your required remote repository, and then place your stashed branch contents into the new clone.
Fast-forward merges literally move your main branch's tip forward to the end of your feature branch. This keeps all commits created in your feature branch sequential while integrating it neatly back into your main branch.
git pull --rebase
. Unlike the other solution, you don't need to know the name of your destination branch.
If your upstream branch is not set, try git pull origin <branch> --rebase
(credit to @Rick in the comments)
Your branch is no longer directly based off of the branch you're trying to merge it into - e.g. another commit was added to the destination branch that isn't in your branch. Thus, you can't fast-forward into it (because fast-forward requires your branch to completely contain the destination branch).
You can rebase your branch on top of the destination branch (git rebase <destination branch>
) to rework the commits such that they will fast forward into it, or you can do a regular merge.
git pull
does not do the trick and if you want to merge both the current changes and the changes that'd come from the pull of the branch from origin then do this:-
git merge origin/BRANCH_NAME
This is because you have enabled the fast-forward only option. The thing here is your pull from the branch will create a merge commit in your local git and the fast-forward only option doesn't allow creating a merge commit at the time of pull.
In the case of a big team, You will end up rebasing and resolving conflicts lots of the time and for each and every commit coming from the pull.
I suggest you remove ff = only line from git local config file.
$ cd to-my-project-root-dir
$ nano .git/config
[pull]
ff = only // remove this line
rebase = false
git pull --no-ff
-> make fast-forwarding to be off by --no-ff
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