3

I am a newbie to git, i just decided to put all of my projects up on github. This is what i did:

  1. Went to my project directory
  2. Went to my github profile, created a new repository. Added a README file and did commit.
  3. On my command line did "git init" and "git add ."
  4. "git commit -m 'source code'" to commit all of my source code in the repo
  5. git remote add origin
  6. git remote -v
  7. And finally "git push origin master" to push the complete source code.

But for some reason, the commit i performed went to a branch called "main" which i never created. The README file i initially created is in the "master" branch. And when i went to the "compare and pull request" option, it showed this message:

There isn’t anything to compare.

main and master are entirely different commit histories.

Can someone please help me with this? What i want to do is add a new repository and put all of my source code in that repository along with a README file. I am not experienced with github

Thank You

musical_ant
  • 143
  • 2
  • 7
  • Does this answer your question? [Difference Between Main Branch and Master Branch in Github?](https://stackoverflow.com/questions/64249491/difference-between-main-branch-and-master-branch-in-github) **tl;dr** Github by default creates a `main` branch instead of a `master` branch for new repositories. If you push to a `master` on one of those you simply create a new (unrelated) branch in that repository). – Joachim Sauer Apr 29 '21 at 13:16
  • @JoachimSauer I understood that they are gonna change the default branch to main instead of master. But the issue becomes, i am unable to merge these two. My first commit was on "merge" branch (README) and than my second commit automatically went to "main". How do i merge these two?? – musical_ant Apr 29 '21 at 13:20
  • [Explanation for the “entirely different” error message](https://stackoverflow.com/a/23350970/1725151) – Guildenstern May 12 '23 at 18:05

4 Answers4

1

After you create a new repo on github, it might list the steps you need to initialize a repo which you'd be able to copy paste. If it's not there, try the following:

cd project-dir
git init
git add --all
git commit -m "Initial commit message"
git remote add origin ssh://git@link_to_your_github_repo
git push -u origin master

This sequence of commands should push everything in your project-dir to the master branch of your new github repo.

PS.

If you're not starting from scratch with a clean repo, you could follow the steps discussed in There isn't anything to compare. Nothing to compare, branches are entirely different commit histories

  • I did exactly that. My first commit was on "merge" branch (README) which i did through the website and than my second commit automatically went to "main" even though i gave :git push origin master command. And now it won't let me merge these two – musical_ant Apr 29 '21 at 13:24
  • My proposal above would require starting from a clean slate, but try the solution discussed in the article below. It details how to merge two branches in a state like yours. https://stackoverflow.com/questions/23344320/there-isnt-anything-to-compare-nothing-to-compare-branches-are-entirely-diffe – Tunc Demircan Apr 29 '21 at 13:28
0

Same issue with me but how I solved it was that I created the remote repository without adding the README.md file, went to my terminal;

git add .
git commit -m "commit message"
git remote add origin url_for_repo
git push -u origin master

You can then add your README.md file on your remote repository after pushing.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0

I had this issue before.

It's because you are in a master branch, you want to change the default branch back to main. You can check what branch you are in using the command

git branch

So the steps you want to do in the terminal are as follows.

git init 
git add .
git status <to see all the files you want to commit>
git  commit -m "Your message"
git branch -M main #THIS WILL SET YOUR BRANCH TO MAIN
git remote add origin <git@github.com:Username/YourRepoName.git>
git push -u origin main
JNC
  • 3
  • 1
0

There is no history of your commits, so you need to commit history first.

git fetch main
git checkout master
git rebase origin/main

This will apply your commit on top of the latest changes from main branch, then conflict may occur resolve it and stage the commit with add then continue and push

git add . 
git rebase --continue
git push origin master --force
Amir Nabaei
  • 1,582
  • 1
  • 15
  • 26