There isn't anything to compare. Nothing to compare, branches are entirely different commit histories

223,189

Solution 1

The Short Answer

It looks like GitHub won't let you compare the branches because they don't actually share any of the same history at all, even though they may share much of the same files and code.

Here is a screenshot of the temporary fork I made of your repo, where I tried to compare master with the upstreambranch, like you described. Notice the error message:

Error message screenshot

It says:

There isn't anything to compare.

master and upstreambranch are entirely different commit histories.

The Long Answer

You probably downloaded the original source and added it to a completely new repo instead of cloning the original repo, right? Doing that will make it so that the history of your repo will be completely different from the history of the original repo, since your new repo won't have any of the same commits with the same sha IDs.

You can see that by doing a reverse log of your master branch and the upstreambranch:

# Your first commit, see commit sha
git log --reverse master
commit c548d7b1b16b0350d7fbdb3ff1cfedcb38051397 # <== HERE
Author: Padraic Stack <[email protected]>
Date:   Wed Apr 2 15:11:28 2014 +0100

    First commit of everything

# First commit sha of the original repo
git log --reverse upstreambranch
commit 105a12817234033c45b4dc7522ff3103f473a862 # <== THERE
Author: Jeremy Boggs <[email protected]>
Date:   Mon Feb 22 16:00:53 2010 +0000

    Creates repo directories for the Seasons theme.

Solutions

If you redo your commits on top of the original history, you should then be able to compare the branches. There are several different ways that you can redo your commits, including

git rebase --onto

and

git cherry-pick

You also can redo each commit manually, if you have to.

Solution 2

If the problem is "main and master are entirely different commit histories.", the following will work

git checkout master   
git branch main master -f    
git checkout main  
git push origin main -f 

Solution 3

I had a similar situation, where my master branch and the develop branch I was trying to merge had different commit histories. None of the above solutions worked for me. What did the trick was:

Starting from master:

git branch new_branch
git checkout new_branch
git merge develop --allow-unrelated-histories

Now in the new_branch, there are all the things from develop and I can easily merge into master, or create a pull request, as they now share the same commit hisotry.

Solution 4

I solve my issue using these commands

git checkout [BRANCH]   
git branch master [BRANCH] -f   
git checkout master   
git push origin master -f

Solution 5

You can force update your master branch as follows:

git checkout upstreambranch  
git branch master upstreambranch -f    
git checkout master  
git push origin master -f

For the ones who have problem to merge into main branch (Which is the new default one in Github) you can use the following:

git checkout master  
git branch main master -f    
git checkout main  
git push origin main -f

The following command will force both branches to have the same history:

git branch [Branch1] [Branch2] -f 
Share:
223,189

Related videos on Youtube

Jack
Author by

Jack

librarian, digital humanist

Updated on July 20, 2022

Comments

  • Jack
    Jack almost 2 years

    I have a CMS theme installed on my machine. I'm tracking changes to it via git and decided to back it up on GitHub so I could share those changes.

    The theme as provided is also available on GitHub. On my machine I have added this as a remote upstream. Now I can easily see the changes between my master and the remote upstream by using the following command:

    git diff --color master upstream/number
    

    If I could add the remote upstream on GitHub I could easily share these changes. Is it possible to set this relationship on GitHub?

    I have tried the following:

    git push -u origin upstreambranch
    

    which adds an upstreambranch to the master on GitHub. However trying to compare both branches doesn't work, the result I get on GitHub is that: "There isn't anything to compare"

    Is there an alternative way to compare these?

    • Admin
      Admin almost 10 years
      It's not clear what you're trying to do. You already pushed your repo up to GitHub? Is it public? If it's public, other people already have access to the code, they can just clone or fork the uploaded repo. "git push -u origin upstreambranch...adds an upstreambranch to the master on GitHub". You don't add branches to "the master on GitHub". Please clarify what you mean.
    • Admin
      Admin almost 10 years
      "However trying to compare both branches doesn't work, the result I get on GitHub is that: 'There isn't anything to compare'". Please explain what you're doing to compare branches on GitHub, and include screenshots if possible.
    • Jack
      Jack almost 10 years
      I am using a cms called Omeka and a particular theme called Seasons. I have modified this theme and uploaded it here: github.com/padraic7a/seasons I would like a visual way (diff) to show people how it is different from the 'original'. I attempted to do so by downloading and then pushing to github this version: github.com/padraic7a/seasons/tree/upstreambranch In the post above I explained how I did that, but that it didn't work. Does that make more sense?
    • Admin
      Admin almost 10 years
      Thanks, that's starting to make a little more sense. Is this the upstream repo that you're referring to? When you say you downloaded the source, did you download it from GitHub or somewhere else, like this site. If you downloaded it from anywhere other than GitHub, then actually doing a fork from GitHub instead would have been better for what you're trying to do, unless this is a customization that you're doing for a specific client that isn't meant to be shared publicly?
    • Admin
      Admin almost 10 years
      I figured out what your immediate problem is, but looking at the bigger picture, you might want to reconsider how you're doing everything, as I've already mentioned in my previous comment...but that depends on what you're ultimately trying to do. Writing an answer for your immediate problem...
    • Jack
      Jack almost 10 years
      I get you, it's certainly a case where I'm beginning from a bad starting point.
    • yoyo
      yoyo about 7 years
      I got into this situation with a git subtree. I used git subtree split to extract changes made in a subtree, pushed the branch to the remote repository from which the subtree originally came, and now I can't merge the changes into any existing branch in that repository. Not sure how to proceed.
    • J.C.
      J.C. over 6 years
      This post on Stackoverflow have the answer. Hope that help.
  • Jack
    Jack almost 10 years
    Thanks for your time on this, I appreciate the effort you put in. Your answer lets me know that what I tried to do isn't possible so I am accepting it. Just to be clear though, I did mention the error above when I said However trying to compare both branches doesn't work, the result I get on GitHub is that: "There isn't anything to compare"
  • Admin
    Admin almost 10 years
    @Jack your welcome. Yes, you did mention that, but you left out the rest of the error message that says "master and upstream are entirely different histories." That was the key to the issue.
  • Admin
    Admin almost 10 years
    @Jack do you know what you need to do to compare branches now? If you redo all of your commits on top of the original history, you can then compare the branches. There are several different ways that you can redo the commits, including git rebase --onto and git cherry-pick.
  • sujay
    sujay over 7 years
    git rebase -i origin/master this worked for me. After doing this I was able to compare both the branches
  • Raja Simon
    Raja Simon over 6 years
    @sujay This is right. After doing that I can compare
  • Tejas Garde
    Tejas Garde over 4 years
    this will make changes of [BRANCH] available in master and you wont be able to create pull request
  • noraj
    noraj almost 4 years
    Your answer is not clear, and I fear it doesn't answer the question. I think the expected answer was to push the changes in an upstream branch to be able to compare them.
  • Peter Lenjo
    Peter Lenjo almost 4 years
    Concise and functional. Thank you.
  • iamgraeme
    iamgraeme over 3 years
    @Susie short for force!
  • Henrique Bruno
    Henrique Bruno over 3 years
    For the new "main" branch as default, you can do this way: git checkout master git branch main master -f git checkout main git push origin main -f
  • Ribena
    Ribena over 3 years
    A line by line breakdown would be useful for beginners. Some of those commands are potentially dangerous.
  • Kuldeep Kumar
    Kuldeep Kumar over 3 years
    I am not a super cool person with git, an explanation will help @blue
  • blueware
    blueware over 3 years
    @TaslimOseni Glad to help
  • MercifulSory
    MercifulSory about 3 years
    I have made your suggested solution and now my old branch is gone, and I cant get to any of the past commits. Thanks!
  • theyCallMeJun
    theyCallMeJun about 3 years
    The first 2 commands can just be collapsed into git checkout -b new_branch. This creates new_branch off the master branch and switches into it.
  • lys
    lys about 3 years
    "The Short Answer" .... "The Long Answer" should be the default SO answer format. Perfect
  • aless80
    aless80 about 3 years
    Any idea how to get rid of the message in green "Compare & Pull Request" leading to a page with "There isn't anything to compare"?
  • George Cscnt
    George Cscnt about 3 years
    @kunal I followed your suggestion but I probably flipped the branches so I ended up missing all the work. How can I revert this? I had a local project that was using master as the branch, when I created the repo in github I tried to merge main into master but I got the error explained in the histories were totally different. I followed your answer but ended putting main on master where I had all my work
  • Quantum
    Quantum almost 3 years
    @user456814 your detailed explanation was really helpful.
  • Kristóf
    Kristóf almost 3 years
    I would almost never suggest using force push. That will "overwrite" the branch state on github. Use the rebase, merge or cherry-pick solutions. Force pushing basically discards the state on the server. This may work if you are the only one using the repository, but it is still a dangerous practice. Use force push only if you absolutely know what you are doing.
  • Jonathan Disla
    Jonathan Disla almost 3 years
    Thank you for this much-needed tip. The result of this instruction was that all of the files that had been placed on the master were moved into the main branch.
  • ASH
    ASH over 2 years
    This didn't work for me, but thanks for helping others. I'll keep looking around
  • ASH
    ASH over 2 years
    to be extra careful, I suggest that everyone creates 2 new branches to experiment with. However, I tried this and it didn't work for me. but thanks for helping others. still digging
  • MrDeveloper
    MrDeveloper over 2 years
    This doesn't appear to answer the question unfortunately. You might try to explain a little more about what your process is trying to accomplish.
  • Admin
    Admin over 2 years
    Please add further details to expand on your answer, such as working code or documentation citations.
  • Manik Sidana
    Manik Sidana over 2 years
    Works for me as well !!! Thanks
  • candyline
    candyline over 2 years
    exactly what I needed thank you
  • Daniel Aldridge
    Daniel Aldridge over 2 years
    YO!!! This did the trick!!! Mucho Love!
  • mr.loop
    mr.loop over 2 years
    Well, this is the method
  • Chris
    Chris about 2 years
    Welcome to Stack Overflow. Please read How to Answer.
  • Lance2k
    Lance2k about 2 years
    this fixed mine, i didn't know want happened but I wasn't able to make a pull request on github. Until this code.
  • debugmode
    debugmode about 2 years
    You save my life. I think this answer has increased point and should seen every person, who having troubleshot .
  • Daniel Melendrez
    Daniel Melendrez almost 2 years
    Same here. Worked for me. Just to clarify for any other n00bs (like me). Replace "origin" with the name of your repo.
  • codergirrl
    codergirrl almost 2 years
    !!Yes it works thanks a lot. Whoever use this please don't forget to backup your changes or you will miss them!!!!
  • Karolina Hagegård
    Karolina Hagegård almost 2 years
    Great explanation... But what's the solution?
  • mfaani
    mfaani almost 2 years
    @KarolinaHagegård just start over the git init. Or like clone the repo on Github into your computer. Then copy/paste all the files into your (other) local repo. merge it. and then push your local repo onto GitHub as a brand new repo. tldr you can't make a first commit from both GitHub and local repo. creating a README (or any other file) counts as a first commit...
  • Karolina Hagegård
    Karolina Hagegård almost 2 years
    That's beautiful...!
  • Karolina Hagegård
    Karolina Hagegård almost 2 years
    Thanks. I already solved my issue in the way I explained in an Answer in this thread, but I think your solutions might be a good alternative! However, please edit your Answer to include your solutions step by step with more detail, rather than leaving them as a comment like this... Comments can be cleared away at any time, and shouldn't be considered part of the Answer. 😉 So they say.