How to do it...

  1. Our template directory is ready, and we can use it, as described earlier, as a command-line option, an environment variable or, as in this example, to be set as a configuration:
$ git config --global init.templatedir ~/.git_template
  1. Now, all Git repositories we create using init or clone will have the default files of the template directory. We can test whether it works by creating a new repository as follows:
$ git init template-example
$ cd template-example
  1. Let's try to create a .txt file and see what git status tells us. It should be ignored by the exclude file from the template directory:
$ echo "this is the readme file" > README.txt
$ git status 

The exclude file worked! You can put in the file endings yourself, or just leave it blank and keep to the .gitignore files.

  1. To test whether the commit-msg hook works, let's try to create a commit. First, we need a file to commit. So, let's create that and commit it as follows:
$ echo "something to commit" > somefile
$ git add somefile
$ git commit -m "Committed something"
  1. We can now check the history with git log:
$ git log -1
commit 1f7d63d7e08e96dda3da63eadc17f35132d24064
Author: John Doe <[email protected]>
Date:   Mon Jan 6 20:14:21 2014 +0100
    
  Committed something
    
  Hi from the template commit-msg hook
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.90.141