Intro
This is a small learning about git.
- --allow-unrelated-histories
- local git copies
Unrelated-histories
Unrelated histories may happen sometimes. Usually, we use git init command and create a git repo. This has some unique identity (I didn't dig into internals, I'm just speculating).
So, how the unrelated histories happen ?
Here are few scenarios, I can think.
- One personally
git init
locally, and done a fair amount of coding. Another person, created git repo just for the first person. - If one person shares a project folder to other without initializing a git repo (ie.
git init
). Then, both of themgit init
at later stage.
Then, you might end-up in unrelated histories. Probably, you will see this error.
fatal: refusing to merge unrelated histories
.
The option to fix this is
--allow-unrelated-histories
For example, see following command
git pull origin master --allow-unrelated-histories https://github/username/reponame.git
local git copies
Say two developers are working on project and both are using git. They can merge git repos locally as well.
git pull /path/to/other-copy
Actually, other operations like clone, pull, etc.
work as well.
Reference
https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories-on-rebase
https://mkyong.com/git/git-pull-refusing-to-merge-unrelated-histories/
https://www.datree.io/resources/git-error-fatal-refusing-to-merge-unrelated-histories
Top comments (2)
I've ran into this a number of times as well. I think you can run into this issue for anything that changes history, such as a rebase. I think its generally ok to
git push --allow-unrelated-histories
to your own repo with no collaborators, or to your own branch, steer clear with a branch that has collaborators.Thanks for sharing your experience and thoughts.