Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where did I branch from?

I got back on an old project and I ran the nice git status to figure out what was going on and I noticed way too many branches! I want to do some housekeeping before starting to work on this again but I'm not sure which branch comes from which..

E.G. Does "branchA" derive from "develop"? Does "branchB" derive from "master" or "branchA"??

How can I answer the sample questions above?

like image 763
Marsellus Wallace Avatar asked Mar 27 '12 21:03

Marsellus Wallace


People also ask

How do I tell which branch I created?

Take a look at config file, perhaps there is branch. <branchname>. merge entry, which would tell you what branch this one is based on. You can also try git show-branch <branch> master , as an alternative.

What is a branch example?

The definition of a branch is a part of a plant stem or a part of something which is larger and more complex. An example of branch is the limb of a tree. An example of branch is the police force as a part of a community's government. Branch means to divide into separate parts or to expand the scope.

How is a branch created?

The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.


2 Answers

git merge-base shows the commit that is the common ancestor of two branches.

Simple usage: git merge-base <branch> <branch> shows the common commit of the two branches.

like image 72
patthoyts Avatar answered Oct 02 '22 15:10

patthoyts


There's no canonical answer for this, since branches are simply pointers to certain commits in a DAG. For instance, master and foo could be pointing at the same commit; if you then create a branch from foo, it's effectively the same as creating a branch from master.

That said, if you visualize the commit graph (via gitk or some other graphical history tool), you can get a general sense of where the branch points are in the commit graph, versus where various branch pointers are pointing.

like image 44
Amber Avatar answered Oct 02 '22 15:10

Amber