welcome welcome - 27 days ago 6x
Git Question

How to associate a commit to a branch

I have started fiddling with Git using this reference and I created some

commit object
s with

The problem is that when I execute
git log
, I get the following error:

fatal: your current branch 'master' does not have any commits yet

I think that
doesn't create and association between the
object and the current branch.

Is there a way to make this association using


Is there a way to make this association using commit-tree?

No, and that's the whole point of git commit-tree: it's what Git calls a plumbing command, that implements just some small part of the whole system. It does one piece of the whole job, the way a valve or pipe or drain or shower-head does just one piece of the job. You need more pieces to assemble a complete shower.

The plumbing piece that updates references (including branch names, but also other references as well) is git update-ref.

(Note that to have a tree you can attach to a commit, you also need git write-tree, which in turn needs you to create and populate the index, e.g., using git update-index. This is all covered in the Git internals page you linked to, but they did leave out the last step with git update-ref.)

If you want to create commits and put them on branches in the usual way, you should use the porcelain commands like git add and git commit. These are intended to be human-friendly (how well they achieve this particular goal is a matter of opinion :-) ).