简体   繁体   English

如何在 GitHub 上使用 master 更新分支

[英]How to update a branch with master on GitHub

I have a Sprint branch that was created prior to new updates on Master.我有一个 Sprint 分支,它是在 Master 上的新更新之前创建的。 Since then, the changes were pushed to the master branch, now I have to update the Sprint branch.从那以后,更改被推送到主分支,现在我必须更新 Sprint 分支。 I am trying to sync my Sprint branch with a master.我正在尝试将我的 Sprint 分支与 master 同步。

Is there a way to do it through github.com page, otherwise I am using PhpStorm VCS.有没有办法通过 github.com 页面做到这一点,否则我正在使用 PhpStorm VCS。

It's simple and can be done by two command lines.这很简单,可以通过两个命令行完成。

git checkout sprint
git merge origin/master

This will merge the remote master branch to the local sprint branch.这会将远程 master 分支合并到本地 sprint 分支。 So your local sprint branch is up to date like master branch.因此,您的本地 sprint 分支与 master 分支一样是最新的。 If you need to do this on Github.com, then create a PR(Pull Request) and then select two branches(base:sprint and compare:master) and then merge it.如果您需要在 Github.com 上执行此操作,则创建一个 PR(拉请求),然后选择两个分支(base:sprint 和 compare:master)然后合并它。

Try merging master branch(with latest changes) to your sprint branch.尝试将 master 分支(具有最新更改)合并到您的 sprint 分支。 This will get your master commits (absent from sprint branch) to your sprint branch.这将使您的主提交(没有 sprint 分支)到您的 sprint 分支。 Then merge your sprint branch(having commits absent from master) to master branch.然后将您的 sprint 分支(在 master 中没有提交)合并到 master 分支。

Through Github Web page通过 Github 网页

1. Raise a pull request from master to sprint branch.
2. Merge the pull request using github's UI.
3. Raise a pull request from sprint branch to master.
4. Merge the pull request.

Through Command Line通过命令行

git checkout master
git pull origin master
git checkout sprint
git merge master
git checkout master
git merge sprint
git push origin sprint

It's worth noting, although not directly requested by you, that Github Desktop has hugely simplified this functionality.值得注意的是,虽然您没有直接要求,但 Github Desktop 已经极大地简化了此功能。 With "Current Repository" set to your repo and "Current Branch" set to your Sprint branch, simply chose from the menus:将“当前存储库”设置为您的存储库并将“当前分支”设置为您的 Sprint 分支,只需从菜单中选择:

Branch->Update from Master ( Ctrl + Shift + U on Windows/Linux or + Shift + U on Mac OSX)分支->从主更新(在 Windows/Linux 上为Ctrl + Shift + U或在 Mac OSX 上为 + Shift + U

Once that's complete, you'll get a "Push Origin" button to push the changes to Sprint.完成后,您将获得一个“Push Origin”按钮以将更改推送到 Sprint。 ( Ctrl + Shift + P or + Shift + P on Mac OSX) Ctrl + Shift + P + Shift + P在 Mac OSX 上)

In short:简而言之:

Ctrl + Shift + U Ctrl + Shift + U

Ctrl + Shift + P Ctrl + Shift + P

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

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