Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

templates - Set up a default directory structure on git init

I would like to optimise my git workflow by automating creation of .gitignore, README, LICENSE and other files on git init command.

To do that I RTFM of git init at http://git-scm.com/docs/git-init and it tells me to do one of the following:

  1. Use git init --template=<template_directory>, but it's bothersome.
  2. Alter the contents of the $GIT_TEMPLATE_DIR environment variable, but I would rather not.
  3. Set the init.templatedir configuration variable. Now we're talking!

So I sudo mkdir /usr/share/git-core/templates/my_template and touch some files in it, then I vim ~/.gitconfig and append:

[init]
    templatedir = /usr/share/git-core/templates/my_template

And git config -l tells me:

...
init.templatedir=/usr/share/git-core/templates/my_template
...

Happy with myself, I go to my development playground directory and:

$ git init
Initialized empty Git repository in /the/current/directory
$ ls -a
.   ..  .git

Bummer... where are the files? :(

Quick check:

$ ls -a /usr/share/git-core/templates/my_template
.   ..  .gitignore  LICENSE README.md
$ git --version
git version 1.8.2.1

It seems that $ git init --template=/usr/share/git-core/templates/my_template doesn't work either.

So what is it that I'm doing wrong here? Incorrect configuration directive? Bad template or its location (I'm on OSX)? Should template be a git repo? A bare one?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The behavior you're seeing is the expected git behavior:

If you read the manual correctly about the template directory:

TEMPLATE DIRECTORY

The template directory contains files and directories that will be copied to the $GIT_DIR after it is created.

The files which are copied from the template directory are placed in your GIT_DIR which defaults to the .git directory under your repo's root directory.

git init does not support templates for the work-tree as far as I know. If this behavior is required, you should be able to get away with writing some simple bash aliases or functions to do this for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...