Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge branches with entirely different commit histories in Github?

I wanted to give Github a try, so I create an account. To train myself, I created a remote repository, cloned into a folder on my computer, and experimented how to push a file I modified to the remote repository. For this, everything is fine.

Now comes the trouble: to experiment further, I created another remote repository, to which I want to push some code from a local repository. The push operation seems to be fine, as the pictures here below show

Picture 1

Picture 2

As you can see, the branch in my remote repository is called "main", and the branch in my local repository is called "master". The problem is when I try to make the changes effective in the remote repository (i.e. when I try to merge "master" into "main" by clicking the "Compare & pull request" button, if I express myself correctly ?), Github tells me that

There isn’t anything to compare. main and master are entirely different commit histories.

Picture 3

hence I cannot put the changes online. Can someone explain me how to solve that problem ?

N.B.: I use Git Bash to have a command line to execute the operations

like image 616
aheuchamps Avatar asked Oct 27 '25 06:10

aheuchamps


2 Answers

Since this is the first commit you need to make sure there is history, so rebase came in help. if conflict happen use git rebase --continue.

git rebase origin/main
git push origin master --force
like image 134
Amir Nabaei Avatar answered Oct 29 '25 07:10

Amir Nabaei


Check the pulldown to switch branches in the remote repository, located on the left just above the code list. You should be able to toggle between the two, and see everything has been pushed into master. That said, I found your question as it is similar to mine... I have that same error "... main and master are entirely different commit histories" - and being new to doing GitHub right - was trying to (or think I should) pull or merge them together. I did read where 'Main' is supposed to replace 'Master', so it is confusing I have ended up with both. Old repos will continue to use master until GitHub announces a 'seamless' transition for them. I suspect in creating my local repo, I used old instructions from before main was in use, that may have added the master branch.

like image 45
MJ_ Avatar answered Oct 29 '25 06:10

MJ_