6. A branch is a note on a commit
A branch is a 41-byte file holding one commit name; it moves when you commit on it; making or deleting it does nothing to the commits.

6. A branch is a note on a commit

A branch is a 41-byte file holding one commit name; it moves when you commit on it; making or deleting it does nothing to the commits.

Cheap branches are the reason Git workflows look the way they do, and "deleting a branch deletes work" is false.

People picture a branch as a copy of the project. It is not.

A branch is a note with a name. It points at one commit. On disk it is a file holding that commit's name. Forty one bytes.

Commit again, and the note moves to the new commit. The commits stay where they are.

Making a branch writes one small file. Deleting one removes the note. The commits it pointed at are untouched.

So a branch is cheap. Make as many as you like. The history is the commits. The notes just mark places, and only move when Git moves them.

Check yourself. You delete a branch. What happens to its commits?

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Connections0

Connections show where other documents or comments link to this document.

Related documents

Loading connections…