This is a model of .gitignore file for your PHP project. It differs from other models you can see, in GitHub for example, because of the use of regular expressions and exceptions, making the file shorter and the rules smarter and more adaptative to any kind of projects.
French users : my original french article for more détails.
If you have local HTTP server with PHP-CLI/SAPI running, being in your project root path, type in console command :
- PHP projects (main rules) :
php -r "readfile('https://raw.githubusercontent.com/tbondois/gitignore/master/php.gitignore');">>.gitignore
- Additional rules for Symfony 2, 3, Silex, Oro Platform, AkeneoPIM :
php -r "readfile('https://raw.githubusercontent.com/tbondois/gitignore/master/symfony2.gitignore');">>.gitignore
- Additional rules for Laravel / Lumen :
php -r "readfile('https://raw.githubusercontent.com/tbondois/gitignore/master/laravel.gitignore');">>.gitignore
- Additional rules for Magento 2 :
php -r "readfile('https://raw.githubusercontent.com/tbondois/gitignore/master/magento2.gitignore');">>.gitignore
- Additional rules for Magento 1 :
php -r "readfile('https://raw.githubusercontent.com/tbondois/gitignore/master/magento1.gitignore');">>.gitignore
or php -r "readfile('https://raw.githubusercontent.com/github/gitignore/master/Magento.gitignore');">>.gitignore
if you want to exclude all core files from your repository.
- Additional rules for Wordpress 4 :
php -r "readfile('https://raw.githubusercontent.com/tbondois/gitignore/master/wordpress4.gitignore');">>.gitignore
git config --edit --global
Insert this (and adapt with the path you want) :
[core]
excludesfile = C:\\Users\\MyUser\\.gitignore
So then you will avoid to annoy your teammates pushing new rules in the .gitignore projects for your IDE or tools.
Very useful for PHP developers (production environments are always GNU/Unix family). You can force that in
- In your IDE : you will need a EditorConfig plugin plugged in your IDE for that. Then, always project root path, type in console command :
php -r "readfile('https://raw.githubusercontent.com/tbondois/gitignore/master/unix.editorconfig');">>.editorconfig
- In your Git config : type
git config --edit --global
for global config orgit config --edit
for only a project config.
Insert/Replace this in your file :
[core]
eol = lf
safecrlf = false
autocrlf = input
whitespace = cr-at-eol
If you can also add this in the config file to optimize your git experience :
[http]
postBuffer = 524288000
[push]
default = matching
[diff]
mnemonicPrefix = true
[credential]
# for windows : wincred. linux : store
helper = wincred
[color]
ui = auto
branch = auto
diff = auto
interactive = auto
status = auto
[alias]
rzh= reset HEAD
df = diff
st = status
aa = add .
acm= commit -am
cm = commit -m
ci = commit
co = checkout
br = branch
lg = log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ad)%Creset'
gl = log --oneline --all --graph --decorate
oops = commit --amend --no-edit
pusha = push -vu origin --all
pushm = push -vu origin master --tags
pushd = push -vu origin develop --tags
pullm = pull origin master
pulld = pull origin develop
mapm = branch --set-upstream-to=origin/master master
mapd = branch --set-upstream-to=origin/develop develop