How do force merge everything i have locally into the remote master?
The issue is that a team member had by mistake created a separate branch (main branch being master) called “Head”. “Head” has the latest code which i now want to over-write to the master (since it is up-to-date with all the code).
When i try to perform “Merge Head into master” i get an error saying “unrelated branches”. I searched on so and found out that i would need to pull the branch (“Head”) locally and then push (or force-push) it to the remote “master” branch to merge the code.
- git added by them renaming conflict - git recognises the same files in the renamed directory as new files
- git merge “deleted by us”
- How to Git Merge while preserving changes in master?
- Why does a 'git pull' not also update the remote branch I pulled from?
- Git Merge some folder
- In Git, how to merge (not checkout) part of files from a long ago branch
I used the following command:
git fetch && git checkout Head and checked it out (cloned it) to local. Now when i try to push it shows that i am 17 commits behind and 3 changes to push.
How do force merge everything i have locally into the remote master ?
I did what das-g told but it seems that the only change i see in remote is that the
Head branch is deleted. The code changes which were originally there in
Head has vanished (or lost!!!). I can see the tags and history but it seems the changes are deleted forever!!!
2 Solutions collect form web for “How do force merge everything i have locally into the remote master?”
It seems from your screenshot and from error message that
Head do not have any common ancestors. If I understood you correctly,
- you want the tip of
masterto have the current content of
Head(and exactly that content, not
Head‘s content merged with the content of
- but you want to have both branch’s history preserved in
master‘s ancestry. (Thus
git checkout master; git reset --hard Headisn’t an option.)
You can either rebase the
Head commits on top of master, as VonC suggests, to produce a linear history, at the price that
Head‘s commits will be re-written.
If you want to preserve
Head‘s commits exactly as they are, you can do a somewhat obscure merge:
First, make sure your local
masteris up-to-date (from your screenshot, it doesn’t seem to be)
git checkout master git merge --ff-only origin/master
The actual merge
git checkout Head git merge --strategy ours master
Get the merge commit into
git checkout master git merge --ff-only Head
You’ll probably want to get rid of the strangely named
git branch -D Head
and to get everything (including the branch deletion) onto the remote repo
git push origin master :Head # should not need a force-push as no commits are discarded on the remote site
First, do not call a branch “Head”: that is very close from HEAD, which references the “current commit”.
You can rename it easily:
git branch -m Head Tip
Regarding the unrelate branch situation, you can try and cherry-pick it on top of master:
git checkout master git checkout -b tmp git cherry-pick Tip~2 Tip~1 Tip git branch -f Tip tmp git checkout Tip
rebase --onto option is a bit more complex)
Once everything looks ok locally, you updtate the new branch name on the remote repo:
git push origin --set-upstream Tip git push origin :Head