git 如何从 GitHub 上的 master 创建开发分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39478482/
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-09 04:31:02  来源:igfitidea点击:

How to create development branch from master on GitHub

gitgithub

提问by smeeb

I created a repo on GitHub and only have a masterbranch so far. My local working copy is completely up to date with the remote/origin masteron GitHub.

我在 GitHub 上创建了一个 repo,master到目前为止只有一个分支。我的本地工作副本与masterGitHub 上的 remote/origin 完全同步。

I now want to create a developmentbranch on GitHub so that other people on my team can start pushing changes to development(instead of directly to master) and submit PRs, request code reviews, etc.

我现在想development在 GitHub 上创建一个分支,以便我团队中的其他人可以开始将更改推送到development(而不是直接推送到master)并提交 PR、请求代码等。

So I tried creating a new developmentbranch locally and pushing it:

所以我尝试development在本地创建一个新分支并推送它:

git checkout -b development
git push origin development:master

But git just says Everything up-to-date. So I ask:

但是 git 只是说Everything up-to-date. 所以我问:

If I'm current with master, how do I just create a remote developmentbranch that contains an exact copy of master?

如果我现在使用master,我如何只创建一个development包含精确副本的远程分支master

回答by ddavison

When you do

当你做

$ git push origin development:master

What's actually happening is git is taking <local>:<remote>and updating <remote>to whatever the <local>branch is.

实际发生的是 git 正在获取<local>:<remote>并更新<remote>到任何<local>分支。

Since you executed git checkout -b developmentfrom master, your local developmenthas all the commits masterdoes; hence it shows as everything is up to date.

由于您git checkout -b development从执行master,您的本地development拥有所有提交master;因此它显示一切都是最新的。

You can just do

你可以做

$ git checkout -b development
$ git push origin development

to push the new branch

推送新分支

回答by Kabard

This works for me

这对我有用

git push origin development

回答by williamdelgato

You can also use git flow. This will automatically create the branch with the right naming convention, it's good practice.

您也可以使用 git flow。这将自动创建具有正确命名约定的分支,这是一种很好的做法。

git flow init

and to push

并推

git push --set-upstream origin develop