1

I want to have the same structure in all new Git repos, for example:

repo
|- .git (created by git-init)
|- src
|- doc
|- README

Of course, in *nix I can have something like alias ginit="git init && mkdir ... && touch ..."

Can I have some kind of hook for git-init to create the dirs and a file only by means of Git itself? As far as I understand, --template= changes the structure of .git only.

homocomputeris
  • 509
  • 5
  • 18
  • Do templates not work here? `git init --template=`? You can configure a default template. – jthill Nov 01 '19 at 16:14
  • @jthill "Files and directories in the template directory whose name do not start with a dot will be copied to the `$GIT_DIR` after it is created." — that is, to `.git`. – homocomputeris Nov 01 '19 at 16:27
  • However, you can have everything all set for an initial `git reset --hard`, try it: `git init --template=path/to/some/.git newrepo; cd newrepo; git reset --hard`. I dare say folding in everything you could write as a oneliner with existing tools is never going to happen, you've got a toolbox, demanding that any tool be expanded to incorporate what all the others there, are there for, is just befuddling. – jthill Nov 03 '19 at 20:38

1 Answers1

1

Have you considered using git aliases? e.g. (untested):

$ git config --global alias.ginit '!git init && mkdir src && mkdir doc && touch README'
$ git ginit
Chris Yungmann
  • 1,079
  • 6
  • 14
  • Not a bad option. `!` means it just sends a command to the shell, so it's basically the same and OS-dependent. – homocomputeris Nov 01 '19 at 15:59
  • I do not believe there is anything built into git that would allow you to do this without shelling out. However, on Windows you have GNU Bash via git bash and on MacOS/Linux you have it natively. You could use a scripting language if you need more cross-platform compat. – Chris Yungmann Nov 01 '19 at 16:59