Ankush Jain
Ankush Jain

Reputation: 7059

What branch GIT considers as source branch while creating new branch?

I am new to GIT & in learning phase of GIT Concepts. I have two simple & quick questions.

Q1. Whenever we want to create a new branch, we type below command:

git checkout -b BranchName

Here, my question is that git checkout consider which branch as it's source branch while creating new branch?

Q2. Suppose, whatever branch which it is considering as source branch is not up to date from remote. So while creating a new branch from that source branch, does it create a pull for the source branch & then create new one OR it considers local branch as it's base and doesn't pull anything from server?

Upvotes: 2

Views: 1033

Answers (2)

Philippe
Philippe

Reputation: 31147

There is no notion of source branch. The branch is what we call a 'ref', a pointer toward a commit.

So when you create a branch, the branch point toward the commit you are on (or indirectly, the first commit pointed by the current branch you are on).

If you don't specify a specific commit via a has or a refspec, git will create the branch on the commit with the following hash that you could get with the command:

git rev-parse HEAD

Upvotes: 2

Attersson
Attersson

Reputation: 4866

It will consider as source your current branch or use one more arg:

git checkout -b BranchName StartPoint

Note: below I answer to Q2:

If the start point is not up to date and you did not commit anything locally, you can pull, otherwise you could rebase it (alternatively you can merge, still using the pull). git fetch --all refreshes history from the remote You may be a few commits behind. Then git rebase origin/master (or whatever the branch) thus updating it and putting your commits on top.

Upvotes: 1

Related Questions