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

Related :   Git filename too long in Windows MINGW / Git Bash

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.


lynxbee_ezoic

Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )

   


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

Leave a Comment

Android Android Applications Android Build system Android Commands 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 & Build Development, Debugging and Performance Tools 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 Audio, Video, Images NDK / Middleware / HAL OS 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 / Bitbake / Openembedded