There isn't anything to compare. Nothing to compare, branches are entirely different commit histories
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:
It says:
There isn't anything to compare.
master
andupstreambranch
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
Related videos on Youtube
Comments
-
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 almost 10 yearsIt'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 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 almost 10 yearsI 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 almost 10 yearsThanks, 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 almost 10 yearsI 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 almost 10 yearsI get you, it's certainly a case where I'm beginning from a bad starting point.
-
yoyo about 7 yearsI 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. over 6 yearsThis post on Stackoverflow have the answer. Hope that help.
-
-
Jack almost 10 yearsThanks 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 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 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
andgit cherry-pick
. -
sujay over 7 yearsgit rebase -i origin/master this worked for me. After doing this I was able to compare both the branches
-
Raja Simon over 6 years@sujay This is right. After doing that I can compare
-
Tejas Garde over 4 yearsthis will make changes of [BRANCH] available in master and you wont be able to create pull request
-
noraj almost 4 yearsYour 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 almost 4 yearsConcise and functional. Thank you.
-
iamgraeme over 3 years@Susie short for force!
-
Henrique Bruno over 3 yearsFor 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 over 3 yearsA line by line breakdown would be useful for beginners. Some of those commands are potentially dangerous.
-
Kuldeep Kumar over 3 yearsI am not a super cool person with git, an explanation will help @blue
-
blueware over 3 years@TaslimOseni Glad to help
-
MercifulSory about 3 yearsI have made your suggested solution and now my old branch is gone, and I cant get to any of the past commits. Thanks!
-
theyCallMeJun about 3 yearsThe first 2 commands can just be collapsed into
git checkout -b new_branch
. This createsnew_branch
off themaster
branch and switches into it. -
lys about 3 years"The Short Answer" .... "The Long Answer" should be the default SO answer format. Perfect
-
aless80 about 3 yearsAny 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 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 almost 3 years@user456814 your detailed explanation was really helpful.
-
Kristóf almost 3 yearsI 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 almost 3 yearsThank 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 over 2 yearsThis didn't work for me, but thanks for helping others. I'll keep looking around
-
ASH over 2 yearsto 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 over 2 yearsThis 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 over 2 yearsPlease add further details to expand on your answer, such as working code or documentation citations.
-
Manik Sidana over 2 yearsWorks for me as well !!! Thanks
-
candyline over 2 yearsexactly what I needed thank you
-
Daniel Aldridge over 2 yearsYO!!! This did the trick!!! Mucho Love!
-
mr.loop over 2 yearsWell, this is the method
-
Chris about 2 yearsWelcome to Stack Overflow. Please read How to Answer.
-
Lance2k about 2 yearsthis fixed mine, i didn't know want happened but I wasn't able to make a pull request on github. Until this code.
-
debugmode about 2 yearsYou save my life. I think this answer has increased point and should seen every person, who having troubleshot .
-
Daniel Melendrez almost 2 yearsSame here. Worked for me. Just to clarify for any other n00bs (like me). Replace "origin" with the name of your repo.
-
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 almost 2 yearsGreat explanation... But what's the solution?
-
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 almost 2 yearsThat's beautiful...!
-
Karolina Hagegård almost 2 yearsThanks. 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.