简体   繁体   English

如何将分支合并到 Github 中的主分支?

[英]How to merge a branch to main branch in Github?

I have my code on my local computer.我的本地计算机上有我的代码。 I created a github repository.我创建了一个 github 存储库。 I wanted to upload my local code to this remote github repository.我想将我的本地代码上传到这个远程 github 存储库。 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:然后我去了我的 github 存储库,我看到了一个新分支:

在此处输入图像描述

So I click on the green button to make a pull request:所以我点击绿色按钮发出拉取请求:

在此处输入图像描述

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'

I hope the master branch contains all of your pushed changes Steps to merge your branch我希望master分支包含您所有推送的更改合并您的分支的步骤

  1. git checkout main git 结账main
  2. git merge master git 合并master
  3. git push origin main git推原点main

Now master is merged in main branch and main branch contains all the changes of master branch.现在master合并到main分支中, main分支包含 master 分支的所有更改。

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.或者您可以 go 到Pull Request选项卡并单击您创建的Pull request然后向下滚动您将能够看到Merge Pull Request按钮。 On clicking that button it will merge your branch into main branch.单击该按钮后,它会将您的分支合并到main分支中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM