8

I have my code on my local computer. I created a github repository. I wanted to upload my local code to this remote github repository. This is what I did on terminal:

  1. I went to the directory of my code from terminal

Then I type:

>git init
>git add .
>git commit -m "First commit"
>git remote add origin https://github.com/usergithub/repository_name.git

Then I went to my github repository and I saw a new branch:

enter image description here

So I click on the green button to make a pull request:

enter image description here

But there is nothing there I can do to merge these 2 branches?

How can I merge the branch to my main project?

I tried different stuff from the terminal:

git push --force origin main

But I get this error message:

error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/usergithub/repository_name.git'
4
  • Is there anything on main to merge with? Or is it the default empty branch github provides? In the latter case, you don't need to merge, just rename one of your two branches to the other. Dec 23, 2021 at 9:51
  • 1
    The error you get on push is because you don't have a local main to push. You could overwrite remote main with git push -f origin master:main though, but remote main branch's contents would be lost (not a problem if it's empty of course). And you would still have a discrepancy, with a remote main and a local master. You'd better settle on either name and delete the other one. Dec 23, 2021 at 9:54
  • @RomainValeri it is an empty default main branch Dec 23, 2021 at 9:58
  • 1
    What name do you intend to use for your branch? If you prefer master, just delete the other with git push origin :main. If you prefer main, rename your local master with git branch -m master main then push it normally. Dec 23, 2021 at 10:01

1 Answer 1

9

I hope the master branch contains all of your pushed changes Steps to merge your branch

  1. git checkout main
  2. git merge master
  3. git push origin main

Now master is merged in main branch and main branch contains all the changes of master branch.

Or you can go to Pull Request tab and click on the Pull request you have created then scroll down you'll able to see the Merge Pull Request Button. On clicking that button it will merge your branch into main branch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.