As we seen in our previous post, “Pushing your first git repository / project to Github” we tried to push our local git to already existing git at GitHub.
While doing this, we had two different independent repositories with separate contents committed at local git and git at GitHub. Now, when we tried to pull remote repositories contents to local git, we got an error “fatal: refusing to merge unrelated histories” as,
$ git pull origin master From https://github.com/lynxbee/git-helloworld * branch master -> FETCH_HEAD fatal: refusing to merge unrelated histories
This can be solved by adding “–allow-unrelated-histories” flag to git pull command as,
$ git pull origin master --allow-unrelated-histories From https://github.com/lynxbee/git-helloworld * branch master -> FETCH_HEAD Merge made by the 'recursive' strategy. README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md
hence using –allow-unrelated-histories flag merges the different histories of two different git
The man page of “git pull” describes the “–allow-unrelated-histories
” flag as,
By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.