question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"refusing to merge unrelated histories" with initial repository

See original GitHub issue

Description

There’s a corner case where your local repository and remote repository can have distinct histories (because they were initialized with their own commit). We should surface this error, but what to do about it properly is an Excellent Question™.

Version

GitHub Desktop version: 0.5.1

OS version: Windows 10

Steps to Reproduce

This is a bit convoluted, apologies.

  • Create a new repository on GitHub, named whatever (I’m calling mine initialized-repository for future reference) and include a README so it gets an initial commit.
  • Open Desktop and create a new repository with the same name (because consistent). Ensure it at least has a README too. Make a note of where you saved it.

Here’s my setup:

screen shot 2017-05-16 at 12 05 20 pm
  • Launch Repository -> Open command prompt to open a shell
  • Run these command to wireup the repositories and the current branch:
git remote add origin https://github.com/{account}/{repo}.git -f
git branch -u origin/master

{account} is the owner and {repo} is whatever named you defined earlier - so for me this is:

git remote add origin https://github.com/shiftkey/initialized-repository.git -f
git branch -u origin/master
  • Remove the repository, then drag-and-drop the folder to add it back in. This should light it up, and you should see this as your Pull button:
  • Press Pull

Expected behaviour: some guidance about resolving these two histories, favouring the remote repository

Actual behaviour: a basic error

screen shot 2017-05-16 at 12 23 29 pm

And the console logs are kind of meh:

- The command `git -c credential.helper= pull --progress origin` exited with an unexpected code: 128. The caller should either handle this error, or expect that exit code.
(anonymous) @ core.ts:145
- core.ts:151 fatal: refusing to merge unrelated histories

(anonymous) @ core.ts:151

Reproduces how often: 100%

Additional Information

Some better messaging around this would be a good start while we figure out the solution path. I’ve opened https://github.com/desktop/dugite/issues/93 to track getting this into the Git bindings first.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

16reactions
fy-kennycommented, Oct 24, 2018

I create a local repository and create another remote repository. then occur the warning maybe, you cloud try:

  1. git rebase
  2. git pull
  3. git push
6reactions
stevewardcommented, Apr 19, 2019

@cookieuon you can use the command git pull origin master --allow-unrelated-histories from the command line to force Git to merge the two separate repositories together. Let me know if you run into any issues with that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix 'fatal: refusing to merge unrelated histories' Git error
Option 2: unstage, stash, clone, unstash, and then commit. The alternative (and longer) way of fixing the fatal: refusing to merge unrelated histories...
Read more >
Git refusing to merge unrelated histories on rebase
The “fatal: refusing to merge unrelated histories” Git error occurs when two unrelated projects are merged (i.e., projects that are not aware of ......
Read more >
How to Solve fatal: refusing to merge unrelated histories
The error fatal: refusing to merge unrelated histories occurs when two unrelated projects are merged into a single branch. This error arises ...
Read more >
How to fix Git fatal error: refusing to merge unrelated histories
The error fatal: refusing to merge unrelated histories usually happens when you try to make the git pull of a remote repository, but...
Read more >
How to Fix Git “Refusing to Merge Unrelated Histories”
More concretely, it provides powerful tooling to generate Spring Data JPA repositories and methods, Flyway Versioned Migrations, Liquibase ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found