Git Init Template
Demonstrates using a template for setting up new Git repositories.
# Hello and welcome to the Alchemists Screencasts! # Today, we'll look at Git Init Template usage. # As you might know, any directory can be initialized as a repository: ls -alhT # While this directory is not a repository, converting it is simple: git init # We can verify we're in a Git repository because my prompt has changed. # ← Notice "master" in the shell prompt. # We also have the `.git` directory as well: ls -alhT # By default, the `.git` directory will have several files: tree .git # As you advance in your Git setup, you might want something more compact. # For instance, all those Git Hook sample files can go. # We don't need the `description` file or `info` directory either. # To streamline our initialization we can use a Git template. # A basic setup, and one I use often, is to use an empty template: mkdir template # Let's prep this directory for re-initialization: rm -rf .git # Now we can initialize a new Git repository. # This time, we'll initialize with the bare minimum of configurations: git init --template template # The `--template` option expects a directory path. # By giving the option an empty path, we bypass the default template. # Notice how much more compact our repository is: tree .git # We now have a Git repository with barest of structures. # Fewer files, means less maintenance. 🎉 # To configure globally (recommended), run: git config --global --add init.templateDir ~/.config/git/template
# With the global configuration set... # ...we can initialize repositories in a consistent fashion. # ...and avoid having to type the `--template` option: rm -rf .git git init tree .git # So far we've been using an empty template for repository initialization. # We can customize further by adding content we might always need. # Let's say we always need a README: touch template/README.adoc tree template # Watch what happens when we use this template: rm -rf .git git init --template template tree .git # Notice how `README.adoc` is pre-populated in our new repository. # There is much you can do with templates. # I encourage you to experiment further. # ...or use an empty template, like I do, for compact/minimal repositories. # Enjoy! # https://www.alchemists.io # ☿ 🜔 🜍 🜂 🜃 🜁 🜄