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

发布于 2024-10-25 13:11:08 字数 109 浏览 2 评论 0原文

我的本地存储库中有一个名为development的分支,我想确保当我将其推送到origin时,它会与origin/master合并。目前,当我推送时,它会添加到远程开发分支。

我该怎么做?

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.

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

左秋 2024-11-01 13:11:09

您还可以通过这种方式隐式引用前一个分支:

git checkout mainline
git pull
git merge -
git push

You can also do it this way to reference the previous branch implicitly:

git checkout mainline
git pull
git merge -
git push
幸福丶如此 2024-11-01 13:11:09

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

切换到分支“master”:

$ git checkout master

从本地存储库合并到master:

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

推送到master:

$ git push

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

Switch to branch ‘master’:

$ git checkout master

Merge from local repo to master:

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

Push to master:

$ git push
坠似风落 2024-11-01 13:11:08
$ git push origin develop:master

或者,更一般地说

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

or, more generally

$ git push <remote> <local branch name>:<remote branch to push into>
辞慾 2024-11-01 13:11:08

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

我会说:

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

 

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.

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

 

木格 2024-11-01 13:11:08
git init
git add .
git commit -m "Add project to Bitbucket example"
git remote add source https://[email protected]/sample/example.git
git push -u -f source master
git init
git add .
git commit -m "Add project to Bitbucket example"
git remote add source https://[email protected]/sample/example.git
git push -u -f source master
她比我温柔 2024-11-01 13:11:08

您可以安装 git 工具 https://git-scm.com/downloads 它可以帮助合并分支到master。我在 RStudio 中创建了一个分支,对其进行处理,并将更改推送到 github。然后,当我想要合并时,我打开了这个 git GUI 工具,导航到包含我的存储库的文件夹,然后将分支合并到 master。我打开 RStudio 检查是否发生了更改,然后从 RStudio 推送到 github。

you can install the git tool https://git-scm.com/downloads and it can help with merging branch to master. I created a branch in RStudio, worked on it, pushed changes to github. Then when I wanted to merge I opened this git GUI tool, navigated to the folder with my repository, then merged the branch to master. I opened RStudio to check if the changes had happened, then pushed to github from RStudio.

丑丑阿 2024-11-01 13:11:08

让我们将其自动化为一个简单的 git Push

Let's automate this down to a simple git push. ????

Example: local branch develop should push to origin/master:

  1. Set the branch's remote (this has likely already been done)

     git branch --set-upstream-to origin
    
  2. Set the remote's push mapping

    git config --local remote.origin.push develop:master
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文