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.
With git 2.28
you can set a global config with this command
git config --global init.defaultBranch {branchName}
Replace {branchName}
with the default branch name
and now whenever you create a new git repo, the default branch will be this.
More details in my video here: https://www.youtube.com/watch?v=YccHk6QlRss
When cloning a repo from GitHub, the default branch gets stored in the HEAD
file:
$ cat .git/refs/remotes/origin/HEAD
ref: refs/remotes/origin/master
If the default branch is changed on GitHub after the repo has been cloned, this is not updated automatically, but can easily be fixed locally:
git remote set-head origin -a
-a
will set refs/remotes/<name>/HEAD according to remote
Or explicitly to a named branch:
git remote set-head origin develop
Now, HEAD
points to the new location:
$ cat .git/refs/remotes/origin/HEAD
ref: refs/remotes/origin/develop
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With