Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git init with option for auto-creation of a default .gitignore

There is a previous post about automatically adding .gitignore, but how would you specify in git init an option which indicates the corresponding .gitignore to add upon git init?

(In other words, be able to specify which .gitignore to use)

Would this be possible using git commands alone, or some shell script?

like image 394
ina Avatar asked Jul 29 '13 19:07

ina


1 Answers

Solution 1

If you want to rely on templates, as indicated in the post you link, using the template directory you should have different template directories, each one having its proper info/exclude file, and use

git init -c --template=/path/to/template

Note that this won't create a .gitignore file, but a .git/info/exclude file, that stays local to this repo and won't be shared when pushed (not the case with .gitignore)

Solution 2

If you don't want to bother with creating directories, but rather get predefined one from the GitHub .gitignore ones, this quick script inits a repo, grabs gitignore from GitHub's predefined one, and makes a first commit with it.

Check available languages here, and be careful first letter must be capitalized.

#!/bin/sh

git init .
curl -o .gitignore --fail --show-error --silent --location https://raw.github.com/github/gitignore/master/$1.gitignore
git add .gitignore && git commit -m "added gitignore from GitHub"

Call the script git-init-more.sh, chmod +x it, and put it in your path, then you can invoke it like this:

$ git init-more Perl
like image 174
CharlesB Avatar answered Sep 22 '22 16:09

CharlesB