How to Solve – 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.

CSGO - How To Fix “Download Incom... x
CSGO - How To Fix “Download Incomplete” Error

2 thoughts on “How to Solve – fatal: refusing to merge unrelated histories”

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux