Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Branching from origin/master vs branching from local master

Assuming we have a remote repository and we clone it locally.

We checkout a master branch so now we have the local master and a remote remotes/origin/master.

I then have to create a new topic branch that will be merged into the remote master once reviewed:

What are the pros and cons of branching from the local master vs the remote equivalent (if there is any difference)?

Do the same arguments apply to long running branches?

EDIT:

I have been trying to track origin/master for my local branches and I noticed a big downside: on TFS it doesn't let you create a pull request. If you want one, you need to push your branch to origin and this will detach it from master and it will track the new remote branch and then create a pull request; is there anything wrong in what I stated? If not, then this is a big reason not to branch from origin/master.

like image 883
Stefano d'Antonio Avatar asked Oct 13 '16 15:10

Stefano d'Antonio


People also ask

What is difference between origin master and origin master?

origin/master is an entity (since it is not a physical branch) representing the state of the master branch on the remote origin . origin master is the branch master on the remote origin .

What is the difference between origin branch and branch?

Here, branch_name is a local branch, whereas origin/branch_name is a remote-tracking branch; it reflects the state of the corresponding branch that lives in origin .

What is the difference between master and origin master in git?

Origin and Master are two different terminologies used when working and managing the git projects. Origin is the name used for the remote repository. Master is the name of the branch.

What is the difference between master branch and main branch?

The master branch is no different than any other branch in a cloned Git repo, except that historically it's been the default name used when the first branch is created. A developer can delete, rename and even re-create the master branch after it's deleted, just like any other Git branch.


1 Answers

Assuming that master is up to date with its remote tracking branch origin/master, there is no actual difference at all.

Branches are just pointers to commits in the history, so when branching off one branch, you are just creating another pointer that points at the same target. That pointer has no relation to the “original pointer/branch”; it only points to a commit. So when you continue working on that new branch, new commits will only reference the base using the parent relationship of commits. The branches itself are completely irrelevant to the history.

Git has a way to add some kind of metadata to branches. However, the standard branching mechanisms, e.g. using git branch or git checkout -b, will not make Git append any additional metadata to the branch.

The only relevant metadata would be the remote tracking branch. But usually, you wouldn’t want to have more than a single branch track the same upstream branch.

So in your case, when you are creating a feature branch or something, just branch off master, or origin/master. It doesn’t really matter.

like image 97
poke Avatar answered Oct 23 '22 04:10

poke