Solved : fatal: refusing to merge unrelated histories

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,

–allow-unrelated-histories
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.

Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question