The global .gitignore file with set of rules is created to ignore files and folders in every git repositories in your system so it applies to all the projects you're working on however, it works differently in vagrant session. When applying steps below in vagrant session, it will only apply to that session and its project. Assuming that you've already SSH-ed into your vagrant working directory. Files to be globally ignored must not be indexed before otherwise global ignore won't work for them.


Check what has to be ignored


As we can see below, there is a useless folder .idea/ which needs to be ignored.


vagrant@symfony:/vagrant$ git branch
* develop
master
vagrant@symfony:/vagrant$ git status
On branch develop
Untracked files:
(use "git add <file>..." to include in what will be committed)

.idea/
.DS_Store/

nothing added to commit but untracked files present (use "git add" to track)

Create global .gitignore file


To make sense, I'm using a descriptive name which is .gitignore_global so you're free to name it as you want. Create the file in your home directory, put .idea and .DS_Store into it, save it and exit.


vagrant@symfony:/vagrant$ echo $HOME
/home/vagrant
vagrant@symfony:/vagrant$ sudo nano /home/vagrant/.gitignore_global

Setup global configuration file


Setup global configuration file "core.excludesfile" to point to your new global .gitignore_global file.


vagrant@symfony:/vagrant$ git config --global core.excludesfile /home/vagrant/.gitignore_global

Check if it worked or not


As we can see below, .idea/ and .DS_Store/ folders have been ignored completely.


vagrant@symfony:/vagrant$ git branch
* develop
master
vagrant@symfony:/vagrant$ git status
On branch develop
nothing to commit, working directory clean

Note


If you by accident added or committed .idea/ folder before then you must run git rm -rf --cached .idea and git rm -rf --cached .DS_Store commands to clear the cache first.