如何将本地 Git 分支推送到远程的 master 分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5423517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:27:09  来源:igfitidea点击:

How do I push a local Git branch to master branch in the remote?

gitgit-branchremote-servergit-push

提问by picardo

I have a branch called develop in my local repo, and I want to make sure that when I push it to origin it's merged with the origin/master. Currently, when I push it's added to a remote develop branch.

我在本地存储库中有一个名为 develop 的分支,我想确保当我将它推送到原点时,它与原点/主库合并。目前,当我推送它时,它被添加到远程开发分支。

How can I do this?

我怎样才能做到这一点?

回答by mipadi

$ git push origin develop:master

or, more generally

或者,更一般地说

$ git push <remote> <local branch name>:<remote branch to push into>

回答by Eugene Sajine

As people mentioned in the comments you probably don't want to do that... The answer from mipadi is absolutely correct if you know what you're doing.

正如人们在评论中提到的那样,您可能不想这样做……如果您知道自己在做什么,那么 mipadi 的答案是绝对正确的。

I would say:

我会说:

git checkout master
git pull               # to update the state to the latest remote master state
git merge develop      # to bring changes to local master from your develop branch
git push origin master # push current HEAD to remote master branch

 

 

回答by Ram

As an extend to @Eugene's answer another version which will work to push code from local repo to master/develop branch .

作为对@Eugene 的回答的扩展,另一个版本将用于将代码从本地存储库推送到 master/develop 分支。

Switch to branch ‘master':

切换到分支“master”:

$ git checkout master

Merge from local repo to master:

从本地 repo 合并到 master:

$ git merge --no-ff FEATURE/<branch_Name>

Push to master:

推送到大师:

$ git push

回答by Shiv Test

Follow the below steps for push the local repo into Master branchenter code here

按照以下步骤将本地 repo 推送到 Master 分支enter code here

$git status

$git 状态