Git under the hood#
Extended content for those interested in how git works under the hood
You can find a recording of the talk (slides) and hands-on tutorial on YouTube which was done for the Data Club seminar between DTU biosustain and DTU bioengineering (see sections in description of Video).
The above Live Demo is not pulling the merge commit after merging the branch on GitHub: github.com/biosustain/git_training_henry_recording
I show the merge commit in the video below, cloining the recording repository in a newly create VSCode sandbox environment above:
Instructions#
create a folder with an empty repository (default
examplesdirectly openend in VSCode on binder)open instruction:
code-server ../README.md(local computer:code ../README.md)git initin console to initialize repo (or via command palette “Git: Initialize Repository”)setup user.name and user.email (see above)
create files, stage them and see what files are created in
.git/objectscommit files and check
.git/objectscreate branches and checkout
.git/refs(git/branchesis a legacy folder,see here)look at
git/HEAD(maybegit/ORIG_HEADif it exists)
try to create your own fork, and try to lauch it on mybinder
Inspect git objects#
git log --format=raw
git cat-file -p <hash> # pretty print
git cat-file -t <hash> # type
# the binary object can also be inspected using different tools,
# which might make it easier to navigate to certain blobs:
cat .git/objects/<2c>/<38c> | zlib-flate -uncompress
You can find the latest objects and compare it to the log
find .git/objects -type f -exec ls -lt {} + | head -n 10
git log --format=raw -n 3
If you wonder what the codes in a tree mean, check this stackexchange answer
What’s happening?#
Can you explain what happens in the following scenarios?
You committed ten commits and did not yet push. Git complains about too much data. You realize that you committed your source data. You delete it and commit again, but the problem still persists.
You commit something and push. You realize your last commit was wrong. You undo it and commit again. Git complains that you cannot push.
Git internals resources#
curious git - detailed intro to the inner workings
git parable - why git came to exist
Videos:
Git-Interals - shows how git works
Scoot Chacon’s “So you thin you know git” talk (FOSDEM 2024), notes on blog


