`git merge -s subtree` always returns “fatal: refusing to merge unrelated histories”





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Maybe I'm not fully understanding how git merge -s subtree works, but when I use it I always get the error "fatal: refusing to merge unrelated histories". (I've been following the following tutorial)



I have the following example project setup.



repo/ -- main repo
lib/ -- lib repo


I put the lib into repo with the command git read-tree --prefix=dir -u lib/master.
Then I update the lib repo. Finally I try to bring the changes back into repo/ with git merge -s subtree lib/master and get that error.



I understand I can ignore the error with --allow-unrelated-histories but that's not helpful, because it'll make everything into a merge conflict.



Here's a full list of commands that I've run to recreate the problem. This recreates those repositories with commits data.



[~]$ mkdir lib-remote repo
[~]$ cd lib-remote/
# Create the remote repo for lib
[~/lib-remote]$ git init --bare
[~/lib-remote]$ git clone . ~/lib
[~/lib-remote]$ cd ~/lib
# Create the local lib repo and commit something
[~/lib]$ touch file
[~/lib]$ git add file
[~/lib]$ git commit -m 'Initial commit'
[~/lib]$ git push -u origin master
[~/lib]$ cd ~/repo
# Create the main repo, brings the lib repo into it, and commits.
[~/repo]$ git init
[~/repo]$ git remote add lib ~/lib-remote
[~/repo]$ git fetch lib
[~/repo]$ git read-tree --prefix=dir -u lib/master
[~/repo]$ git add -A
[~/repo]$ git commit -am 'Initial commit'
[~/repo]$ cd ~/lib
# Commit a change to the lib repo
[~/lib]$ echo revision >> file
[~/lib]$ git commit -am 'Revision'
[~/lib]$ git push
[~/lib]$ cd ~/repo
# Attempt to merge those changes into the main repo
[~/repo]$ git merge -s subtree lib/master









share|improve this question





























    0















    Maybe I'm not fully understanding how git merge -s subtree works, but when I use it I always get the error "fatal: refusing to merge unrelated histories". (I've been following the following tutorial)



    I have the following example project setup.



    repo/ -- main repo
    lib/ -- lib repo


    I put the lib into repo with the command git read-tree --prefix=dir -u lib/master.
    Then I update the lib repo. Finally I try to bring the changes back into repo/ with git merge -s subtree lib/master and get that error.



    I understand I can ignore the error with --allow-unrelated-histories but that's not helpful, because it'll make everything into a merge conflict.



    Here's a full list of commands that I've run to recreate the problem. This recreates those repositories with commits data.



    [~]$ mkdir lib-remote repo
    [~]$ cd lib-remote/
    # Create the remote repo for lib
    [~/lib-remote]$ git init --bare
    [~/lib-remote]$ git clone . ~/lib
    [~/lib-remote]$ cd ~/lib
    # Create the local lib repo and commit something
    [~/lib]$ touch file
    [~/lib]$ git add file
    [~/lib]$ git commit -m 'Initial commit'
    [~/lib]$ git push -u origin master
    [~/lib]$ cd ~/repo
    # Create the main repo, brings the lib repo into it, and commits.
    [~/repo]$ git init
    [~/repo]$ git remote add lib ~/lib-remote
    [~/repo]$ git fetch lib
    [~/repo]$ git read-tree --prefix=dir -u lib/master
    [~/repo]$ git add -A
    [~/repo]$ git commit -am 'Initial commit'
    [~/repo]$ cd ~/lib
    # Commit a change to the lib repo
    [~/lib]$ echo revision >> file
    [~/lib]$ git commit -am 'Revision'
    [~/lib]$ git push
    [~/lib]$ cd ~/repo
    # Attempt to merge those changes into the main repo
    [~/repo]$ git merge -s subtree lib/master









    share|improve this question

























      0












      0








      0








      Maybe I'm not fully understanding how git merge -s subtree works, but when I use it I always get the error "fatal: refusing to merge unrelated histories". (I've been following the following tutorial)



      I have the following example project setup.



      repo/ -- main repo
      lib/ -- lib repo


      I put the lib into repo with the command git read-tree --prefix=dir -u lib/master.
      Then I update the lib repo. Finally I try to bring the changes back into repo/ with git merge -s subtree lib/master and get that error.



      I understand I can ignore the error with --allow-unrelated-histories but that's not helpful, because it'll make everything into a merge conflict.



      Here's a full list of commands that I've run to recreate the problem. This recreates those repositories with commits data.



      [~]$ mkdir lib-remote repo
      [~]$ cd lib-remote/
      # Create the remote repo for lib
      [~/lib-remote]$ git init --bare
      [~/lib-remote]$ git clone . ~/lib
      [~/lib-remote]$ cd ~/lib
      # Create the local lib repo and commit something
      [~/lib]$ touch file
      [~/lib]$ git add file
      [~/lib]$ git commit -m 'Initial commit'
      [~/lib]$ git push -u origin master
      [~/lib]$ cd ~/repo
      # Create the main repo, brings the lib repo into it, and commits.
      [~/repo]$ git init
      [~/repo]$ git remote add lib ~/lib-remote
      [~/repo]$ git fetch lib
      [~/repo]$ git read-tree --prefix=dir -u lib/master
      [~/repo]$ git add -A
      [~/repo]$ git commit -am 'Initial commit'
      [~/repo]$ cd ~/lib
      # Commit a change to the lib repo
      [~/lib]$ echo revision >> file
      [~/lib]$ git commit -am 'Revision'
      [~/lib]$ git push
      [~/lib]$ cd ~/repo
      # Attempt to merge those changes into the main repo
      [~/repo]$ git merge -s subtree lib/master









      share|improve this question














      Maybe I'm not fully understanding how git merge -s subtree works, but when I use it I always get the error "fatal: refusing to merge unrelated histories". (I've been following the following tutorial)



      I have the following example project setup.



      repo/ -- main repo
      lib/ -- lib repo


      I put the lib into repo with the command git read-tree --prefix=dir -u lib/master.
      Then I update the lib repo. Finally I try to bring the changes back into repo/ with git merge -s subtree lib/master and get that error.



      I understand I can ignore the error with --allow-unrelated-histories but that's not helpful, because it'll make everything into a merge conflict.



      Here's a full list of commands that I've run to recreate the problem. This recreates those repositories with commits data.



      [~]$ mkdir lib-remote repo
      [~]$ cd lib-remote/
      # Create the remote repo for lib
      [~/lib-remote]$ git init --bare
      [~/lib-remote]$ git clone . ~/lib
      [~/lib-remote]$ cd ~/lib
      # Create the local lib repo and commit something
      [~/lib]$ touch file
      [~/lib]$ git add file
      [~/lib]$ git commit -m 'Initial commit'
      [~/lib]$ git push -u origin master
      [~/lib]$ cd ~/repo
      # Create the main repo, brings the lib repo into it, and commits.
      [~/repo]$ git init
      [~/repo]$ git remote add lib ~/lib-remote
      [~/repo]$ git fetch lib
      [~/repo]$ git read-tree --prefix=dir -u lib/master
      [~/repo]$ git add -A
      [~/repo]$ git commit -am 'Initial commit'
      [~/repo]$ cd ~/lib
      # Commit a change to the lib repo
      [~/lib]$ echo revision >> file
      [~/lib]$ git commit -am 'Revision'
      [~/lib]$ git push
      [~/lib]$ cd ~/repo
      # Attempt to merge those changes into the main repo
      [~/repo]$ git merge -s subtree lib/master






      git merge version-control






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 9 at 0:42









      Scotty JamisonScotty Jamison

      111




      111






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1403729%2fgit-merge-s-subtree-always-returns-fatal-refusing-to-merge-unrelated-histor%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1403729%2fgit-merge-s-subtree-always-returns-fatal-refusing-to-merge-unrelated-histor%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар