Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does branching in git create a parent-child relationship?

Tags:

git

git-branch

If I do

$ git branch a
$ git checkout a
Switched to branch 'a'
$ git branch b
$ git checkout b
Switched to branch 'b'
$ git branch c1
$ git branch c2

Is there any relationship between these branches, or are there all considered 'flat' because there weren't any commits in them? In SVN, I would model these branches like this:

master
|
+-a
  |
  +-b
    |
    +-c1
    |
    +-c2

However, when I try to follow this question and do gitk master a b c1 c2, I get a flat line, not the diagram I put above.

like image 366
ripper234 Avatar asked May 27 '11 15:05

ripper234


1 Answers

git doesn't have a strict parent branch, it just has a particular commit path. In this case, they all have the same commit as their starting point, so they're all the same. As soon as they start having their own commits, they'll be their own "lines", but they won't really have a relationship to one-another.

At any point though you can easily merge with any branch using git merge, so the "parent" relationship isn't all that fundamental. Git does have the concept of a parent for the case of using --track (where you receive your parents commits), but this is just a special convenience function. You could easily have any number of "parents" if you dot your I's and cross your T's (git merge branch A, git merge branch B, etc).

like image 130
Chris Eberle Avatar answered Oct 13 '22 23:10

Chris Eberle