.gitignore is the primary way to untrack files and folders. But, what if you want to do the same without using .gitignore file ?
- Ignoring untracked files ie files that are new or has not been added to git yet.
Note: the .git/info/exclude file doesnot get uploaded to remote.
$ touch my_local_file.txt; # Lets say, you don't want this file to be tracked by git.
$ git status -s; # You can see that git detects this file, but you don't want this to happen.
$ cd .git;
$ echo "my_local_file.txt" >> info/exclude;
# Note: you can add contents here just like you do in .gitignore file.
$ git status -s; # Now, the file doesnot show up here.
$ git ls-files --others; # To verify, you should be able to see your file here. The flag --others shows only untracked files.
# In case, you want to version this file, just remove the entry in .git/info/exclude.
- Ignoring changes in files that are already tracked by git.
$ git update-index --assume-unchanged app/config/local/database.php;
Now on, changes in database.php are not tracked anymore by git. So, I can update it to my liking without fear of getting uploaded to remote.
$ git ls-files --others --exclude-from=.git/info/exclude; # To show the files ignored by .gitignore only.