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:- Node.js: git-hooks or husky
- Python: Pre-commit
- PHP: php-git-hooks or GrumPHP
- Shell: GitHooks or Bazze's gist
- Go: GitHooks
git config core.hooksPath someotherfolder
will change git config, but it's still a user-specific setting, so you can't publish it to your team.
.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 inC:\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 usegit 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.
Here's some interesting configuration I have in my user-specific ("global") ~/.gitconfig
:
- I've set my default branch name to
main
with this:[init] defaultBranch = main
- Git will auto-correct typos. If I type
git staas
, it'll rungit status
instead.
The[help] autocorrect = 8
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:
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[core] editor = \"C:\\Users\\Rob\\AppData\\Local\\Programs\\Microsoft VS Code\\bin\\code\" --wait
:q!
.) With this setting, it uses a different editor. - I really like this alias (shortcut):
I frequently start typing[alias] git = !git $@
git
then get distracted, then return and typegit status
or another command. Therefore my command becomesgit git status
. With this alias, if there's agit git
, it takes the rest and runs it as a shell command. Sogit git status
runsgit status
. It just works ... as doesgit git git git git status
. - Another alias I really enjoy:
git hist
:
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[alias] hist = log --oneline --graph --decorate --all
git hist
will get it done. - Want to see all the files in the directory that aren't committed?:
Now I type[alias] ls-ignored = ls-files --others --directory --no-empty-directory
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:
[alias]
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!