Warm tip: This article is reproduced from stackoverflow.com, please click
git github

Change from master to a new default branch git

发布于 2020-04-08 23:41:02

Here is a scenerio:

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

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

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?

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

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

As you can see

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.

Questioner
Harry
Viewed
69
Oliver Evans 2018-07-11 06:19

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.

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

git checkout -b develop

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.

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.

In short, when you do

git pull origin master

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.

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

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

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

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