从master更改为新的默认分支git [英] Change from master to a new default branch git

查看:255
本文介绍了从master更改为新的默认分支git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个场景:

我们有一个默认的分支Master,我们以此为基础进行工作,创建分支并向上推等等.

We have a default branch Master and we work off from this, creating branches and pushing up etc...

我们现在在 Master 上创建了一个 Develop 分支,并将其设置为默认的开发分支.

We have now created a Develop branch off Master and set this as a default development branch.

我想知道的是,现在如何知道我的git pull命令是否正在通过命令行从默认分支请求更改?或指向这个新的默认分支?

What I would like to know is, how do I now know if my git pull command is requesting changes from the default branch via the command line? or point to this new default branch?

我做了什么: -由于创建了一个新的默认分支git,因此从原点/主节点拉入我的主节点

What I have done: - Since creating a new default branch git pull into my master from origin/master

还有任何neww分支,是来自Master还是Develop?

Also, any neww branch, will it be from Master or Develop?

如您所见

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
PS C:\Users\dir\Documents\GitHub\repo> git log
commit 867cxx

fd956f73dc91d0022b (HEAD -> master, origin/master, origin/develop, origin/HEAD)

更新: 默认分支的这种更改是在克隆存储库之后发生的.

update: this change of default branch occurred after cloning the repo.

推荐答案

据我所知,git没有默认分支"的概念.诸如GitHub之类的用户界面确实具有默认分支,即在您打开网页时,默认情况下会看到某个分支(通常是主分支).但是就git而言,master分支并不特殊,它只是赋予第一个分支的名称.

As far as I know, git has no concept of a "default branch". User interfaces such as GitHub do have a default branch in the sense that when you open the web page, you see a certain branch (generally master) by default. But just speaking about git, the master branch is not special, it's just the name given to the first branch.

要创建新分支,请在checkout中使用-b标志,如下所示:

To create a new branch, use the -b flag with checkout, as in:

git checkout -b develop

git branch命令将列出所有现有分支,并且在当前分支旁边带有*.您所做的所有提交都会添加到当前分支中.

The git branch command will list all of the existing branches, with a * next to the current branch. Any commits you make will be added to the current branch.

在您的问题中,您提到从远程拉出.相关概念是跟踪分支机构";请参阅 https://git-scm上具有该名称的部分. com/book/id/v2/Git-Branching-Remote-Branches .

In your question, you mention pulling from a remote. The relevant concept is "Tracking Branches"; see the section with that name at https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches.

简而言之,当您这样做

git pull origin master

它将从origin存储库的master分支中提取更改到当前检出的任何分支中.如果需要,您可以设置远程跟踪,以便git可以根据已签出的分支知道要从何处提取信息.

it will pull changes from the master branch of the origin repository into whichever branch is currently checked out. If you'd like, you can set up remote tracking so that git already knows where you want to pull from based on which branch you have checked out.

例如如果您有远程develop-remote分支和本地develop-local分支,则可以通过以下方式将本地分支设置为跟踪远程分支:

e.g. if you have a remote develop-remote branch and a local develop-local branch, you can set your local branch to track the remote branch via:

git checkout develop-local
git branch --set-upstream-to origin/develop-remote

此外,它们可能都简称为develop,为了清楚起见,在这里我将它们区分开.

Also, they might both be simply called develop, I just distinguished them here for clarity.

最后,我应该提一下,当您执行git pull <url-of-repo>时,会自动建立远程跟踪.

Finally, I should mention that when you do git pull <url-of-repo>, remote tracking is automatically established.

P.S.有关遥控器的更多信息(例如origin是什么意思?),请参见 https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes

P.S. for more information about remotes (e.g. what does origin mean?), see https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes

这篇关于从master更改为新的默认分支git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆