Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge a branch to main branch in Github?

Tags:

git

github

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'
like image 549
Gauthier Buttez Avatar asked Nov 28 '25 19:11

Gauthier Buttez


1 Answers

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.

like image 179
Monish Khatri Avatar answered Dec 01 '25 16:12

Monish Khatri