Skip to content

Chapter_8

Chris McIntosh edited this page Dec 3, 2019 · 1 revision

8 - Customizing Git

1 - Git Configuration

  • git config --system writes to /etc/gitconfig
  • git config --global writes to ~/.gitconfig
  • git config --local writes to .git/config
  • git config --global commit.template <file> allows you to specify a commit log template
  • git config --global help.autocorrect <n> will enable autocorrect and give you n tenths of seconds to cancel
  • git config --global core.autocrlf input will fix crlf on commit

2 - Git Attributes

  • .gitattributes file allows you to set attributes about file types
    • You can also set custom attributes about those files, for instance set up a ms word diff type that runs a custom script to allow you to diff word files
  • You can write Smudge filters
  • Or Clean filters to do keyword expansion like CVS?
  • export-ignore will ignore said files during a git archive command

3 - Git Hooks

Client Side Hooks

  • pre-commit runs first, before even a message is typed
    • git commit --no-verify skips this hook
  • prepare-commit-msg runs after the default message is created and allows you to alter it
  • commit-msg allows you to validate the commit message, to enforce that whatever you want is in every commit message
  • post-commit runs after the commit and doesn't have any parameters, often used for notification
  • Email workflow hooks exist but aren't used much these days
  • pre-rebase allows you to do some validation before a rebase, such as prevent rebase to commits that have been pushed
    • Is that what enables the force push/rebase stuff?
  • post-rewrite runs when you are fixing history
  • post-checkout runs after checkout, is this how git-lfs grabs files?
  • post-merge after a merge
  • pre-push
  • pre-auto-gc before a garbage collection

Server Side Hooks

  • pre-receive runs when handling a push from a client
  • update runs once per branch, similar to the previous one, but pre-receive runs once per push no matter how many branches
  • post-receive runs after the entire process is done