2

I created a .gitignore_global file in ~/Users/Tony/.gitignore_global, which is also the path where the .gitconfig is stored.

This is what is inside the .gitconfig:

[core]
    excludesfile = ~/.gitignore_global

This is what is inside the .gitignore_global:

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# CocoaPods #
#############
Pods

# SVN #
#######
*.svn
.svn/*

# Xcode #
#########
build/
DerivedData
profile
xcuserdata
!default.mode1v3
!default.mode2v3
!default.pbxuser
!default.perspectivev3
*.mode1
*.mode1v3
*.mode2v3
*.moved-aside
*~.nib
*.pbxuser
*.perspective
*.perspectivev3
*.swp
*.xccheckout

I do not understand why the .gitignore_global file isn't working. The .DS_Store files are still being detected by git.
I had already tried comments like "git rm --cached .DS_Store" and tried others solutions found on Stack Overflow, however git is still detecting the .DS_Store files.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Tony Ong
  • 69
  • 9

1 Answers1

1

To be sure your global gitignore is taken into account:

  • make sure you have git 2.8+
  • do a git config --show-origin -l|grep excludesfile to see if your rule is there (if there is one below it involving excludesfile, it would override yours).
  • try and put a full path in your global config for the excludefile: /home/<user>/.gitignore_global instead of '~'.
  • do a git check-ignore -v -- path/to/.DS_Store to see if any ignore rule is displayed.

Since the OP confirms this is working in a new repo, that means the current elements are tracked in the existing repo.
For instance:

git rm --cached -r .DS_Store

Instead, the OP Tony Ong adds in the comments:

I took a round about to solve the problem with regards to "existing repo".
I went to copy the content in the repo to a temp folder, delete the content in the repo, commit/push the repo, copy the content from temp folder to repo, commit/ push again.
It is a tedious process but it works, gitignore_global is now working for existing repo.
I will try "git rm --cached -r .DS_Store" when the opportunity arise.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I did a "git config --show-origin -l|grep excludesfile" and the terminal return me - file:/usr/local/git/etc/gitconfig core.excludesfile=~/.gitignore - file:/Users/Tony/.gitconfig core.excludesfile=/Users/Tony/.gitignore_global there is one below it involving "excludesfile", does it means it will override mine? – Tony Ong Apr 29 '16 at 07:59
  • I did some testing, however the .gitignore_global is not working. I completed point 1 and 3 of yours. don't quite understand point 2 but still run the command and pasted the result earlier on. tried running point 4 but it isn't working. – Tony Ong Apr 29 '16 at 08:05
  • @TonyOng Can you initialize a new repo anywhere you want? `giti init newrepo; cd newrepo`, and create one of the file which should be ignored: a `git status` should *not* show that file (no add or commit necessary) – VonC Apr 29 '16 at 08:07
  • it works for the testing new repo file. however for existing repo, it isn't working. I am thinking i need to untracked the .DS_Store from git in those existing repo first. – Tony Ong Apr 29 '16 at 09:28
  • @TonyOng I confirm: `git rm --chached -r .DS_STore` – VonC Apr 29 '16 at 10:30
  • thanks VonC. I took a round about to solve the problem with regards to "existing repo". I went to copy the content in the repo to a temp folder, delete the content in the repo, commit/push the repo, copy the content from temp folder to repo, commit/ push again. It a tedious process but it works, gitignore_global is now working for existing repo. I will try "git rm --cached -r .DS_Store" when the opportunity arise. thanks man! :) – Tony Ong May 03 '16 at 06:38
  • @TonyOng Thank you for this feedback. I have included your conclusion in the answer for more visibility. – VonC May 03 '16 at 06:40