Skip to contentSkip to conversation

is there a way to reference the branch point?

DISCUSSION layer 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore

layer

author
#0 lore raw

If I make a branch `foo' off master, commit a bunch of times, is there a way to reference the place on master from which I branched?

Thanks.

Kevin

#1 lore raw

Heya,

Quoted 2 lines · layer

If I make a branch `foo' off master, commit a bunch of times, is there a way to reference the place on master from which I branched?

Depends, if you make a new branch from master, you can use 'git merge-base', so:

$ # on master
$ git checkout -b foo-topic-branch
$ # work work
$ git commit
$ # work work
$ git commit

Now you want to know where you branches off from master:

$ git merge-base foo-topic-branch master

That will show you the commit you branches off from, even if master has grown new commits since then.

Signature · 3 lines
Cheers,

Sverre Rabbelier
author
#2 lore raw
Quoted 16 lines · Sverre Rabbelier
Quoted 16 lines

Heya,

Quoted 2 lines · layer

If I make a branch `foo' off master, commit a bunch of times, is there a way to reference the place on master from which I branched?

Depends, if you make a new branch from master, you can use 'git merge-base', so:

$ # on master
$ git checkout -b foo-topic-branch
$ # work work
$ git commit
$ # work work
$ git commit
Quoted 6 lines
Quoted 6 lines

Now you want to know where you branches off from master:

$ git merge-base foo-topic-branch master

That will show you the commit you branches off from, even if master has grown new commits since then.

That works, but what if I don't know it's off master? Normally, a human would, but what if this is a script I'm writing?

Thanks.

Kevin