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).

Talk: Recording of talk

Live Demo: Live Demo of Hands On part

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:

Live Demo Hand on Addon

Instructions#

  • create a folder with an empty repository (default examples directly openend in VSCode on binder)

  • open instruction: code-server ../README.md (local computer: code ../README.md)

  • git init in 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/objects

  • commit files and check .git/objects

  • create branches and checkout .git/refs (git/branches is a legacy folder,see here)

  • look at git/HEAD (maybe git/ORIG_HEAD if 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#