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?
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
)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With