Skip to content

"refusing to merge unrelated histories" with initial repository #1484

Closed

Description

@shiftkey

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 desktop/dugite#93 to track getting this into the Git bindings first.

Activity

  1. self-assigned this
    on Jun 8, 2017
  2. added this to the M5: Post-Beta Bougie milestone on Jun 8, 2017
  3. removed their assignment
    on Jun 24, 2017
  4. shiftkey commented on Jun 24, 2017

    @shiftkey
    MemberAuthor

    There's a more descriptive error in here from an update to duguite, but we need some flow around this to get the user to a happy place.

    Putting this aside for the moment.

  5. removed this from the M5: Post-Beta Bougie milestone on Jun 27, 2017
  6. added
    bug
    and removed
    bug
    on Jun 29, 2017
  7. joshaber commented on Jun 29, 2017

    @joshaber
    Contributor

    Thanks for the suggestion!

    This idea is interesting for the future, but this is beyond the scope of our current roadmap.

    I'm going to add the future-proposal label to this issue and close it out, so that we don't get overwhelmed with our backlog! We'll revisit these as part of our next planning session.

  8. fy-kenny commented on Oct 24, 2018

    @fy-kenny

    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
  9. billygriffin commented on Dec 19, 2018

    @billygriffin
    Contributor

    @shiftkey This feels sufficiently edge-casey to potentially allow it to surface more frequently before we consider solving for it. Would you be ok with removing future proposal here?

  10. shiftkey commented on Dec 20, 2018

    @shiftkey
    MemberAuthor

    @billygriffin yeah, I'm happy to let this sit. But keep in mind we've also seen #1308 #2247 and #5012 mention this particular Git error...

  11. cookieuon commented on Apr 14, 2019

    @cookieuon

    Hey @shiftkey I've just reproduced this fault in 1.6.5, but no error is presented as in your initial post. I try to push, and I am informed the remote is newer than local, I should fetch the remote. Click Fetch, thinks for a second then goes away. Try to push again, rinse and repeat.
    I had to go to the CLI to be presented with the error: "fatal: refusing to merge unrelated histories"

    Hope this isn't in the wrong place.

  12. steveward commented on Apr 19, 2019

    @steveward
    Contributor

    @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.

  13. billygriffin commented on Jun 17, 2019

    @billygriffin
    Contributor

    Going to remove future proposal for now, with the caveat that this may resurface from users and we'll be able to reference this issue if/when it does. Thanks for clearly laying it out @shiftkey!

  14. Mr-HaleYa commented on Aug 25, 2020

    @Mr-HaleYa

    Created a new repo, cloned it onto desktop, created a Readme.md using the website then tried uploading files and the error happens
    image

    The best way I found to deal with it is to create a new branch and push to that then merge afterward

  15. tierninho commented on Aug 25, 2020

    @tierninho
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions