Skip to content

Instantly share code, notes, and snippets.

Last active July 24, 2023 12:06
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save robrich/c0afe83910010913906e5d72bb27d748 to your computer and use it in GitHub Desktop.
Save robrich/c0afe83910010913906e5d72bb27d748 to your computer and use it in GitHub Desktop.
the definitive deep dive into the .git folder

the definitive deep dive into the .git folder

Thanks for joining us for "the definitive deep dive into the .git folder". It's an incredible live-demo where we open every file in the .git folder and show what it does.


Here's the links we saw:

  • git-explorer is a visualization tool I wrote to look not only at commits but at tree nodes and blob nodes inside the objects folder.
  • A Stack Overflow answer about how to un-zlib-compress an object in the .git/objects folder.
  • Use a tool to symlink .git/hooks files into a place that you can commit and share:
  • .git/config is the local configuration for your repo. It overrides the "global" (user-specific) config in ~/.gitconfig which overrides the "system" config in your git install directory. Mine is in C:\Program Files\Git\etc\gitconfig.
  • What's in the .git/index file is a great Stack Overflow post listing the format of index files in Git.
  • gin is a Python program for reading the .git/index file. Or you could use git ls-files.
  • Eric Potter has a great infographic showing all the files inside the .git folder, breaking them nicely into the standard groups: commits (objects), human-readable labels (refs), automation (hooks), configuration, log files, and temp files.
  • Nick Quaranto has an excelent post on git ready with a good summary of all the files in the .git folder, and a great review of this talk.

.gitconfig settings

Here's some interesting configuration I have in my user-specific ("global") ~/.gitconfig:

  • I've set my default branch name to main with this:
      defaultBranch = main
  • Git will auto-correct typos. If I type git staas, it'll run git status instead.
      autocorrect = 8
    The 8 is tenths-of-a-second. So in my case it'll wait 0.8 seconds before running, giving me a chance to change my mind if I don't like the suggestion.
  • I've set my default editor to VS Code:
      editor = \"C:\\Users\\Rob\\AppData\\Local\\Programs\\Microsoft VS Code\\bin\\code\" --wait
    By default any time Git wants to ask me something, it lands in VI which may be less than ideal for new users. (The magic answer is :q!.) With this setting, it uses a different editor.
  • I really like this alias (shortcut):
      git = !git $@
    I frequently start typing git then get distracted, then return and type git status or another command. Therefore my command becomes git git status. With this alias, if there's a git git, it takes the rest and runs it as a shell command. So git git status runs git status. It just works ... as does git git git git git status.
  • Another alias I really enjoy: git hist:
      hist = log --oneline --graph --decorate --all
    I don't use aliases during talks, but it can be a mouth-full to remember all the arguments to display a pretty git history on the terminal. I've taught my fingers that git hist will get it done.
  • Want to see all the files in the directory that aren't committed?:
      ls-ignored = ls-files --others --directory --no-empty-directory
    Now I type git ls-ignored and it'll show me all the files that were excluded by the .gitignore file.

The format of this file is an ini file. So you only need the section header once. If you wanted to include all the aliases listed above, you'd add it like this:

  git = !git $@
  hist = log --oneline --graph --decorate --all
  ls-ignored = ls-files --others --directory --no-empty-directory


Hit me up on Twitter @rob_rich and let's continue chatting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment