0

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

  • 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

1 Answers1

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