Q:

Can't ignore UserInterfaceState.xcuserstate

I'm using Git for Xcode 4 project version control.   I've explicitly added ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate to .gitignore, but Git it won't ignore it.   Any ideas why this is so? 

A:

Git is probably already tracking the file. 
From the gitignore docs:

To stop tracking a file that is currently tracked, use git rm --cached. 

Use this, replacing [project] and [username] with your info:
git rm --cached [project].xcodeproj/project.xcworkspace/xcuserdata/[username].xcuserdatad/UserInterfaceState.xcuserstate
git commit -m "Removed file that shouldn't be tracked"

Alternatively you can use the -a option to git commit that will add all files that have been modified or deleted. 
Once you've removed the file from git, it will respect your .gitignore. 

A:

In case that the ignored file kept showing up in the untracked list, you may use git clean -f -d
to clear things up.  
1. 
git rm --cached {YourProjectFolderName}.xcodeproj/project.xcworkspace/xcuserdata/{yourUserName}.xcuserdatad/UserInterfaceState.xcuserstate

2. 
git commit -m "Removed file that shouldn't be tracked"

3. 
    WARNING first try git clean -f -d --dry-run, otherwise you may lose uncommited changes. 
Then:
    git clean -f -d

A:

All Answer is great but here is the one will remove for every user if you work in different Mac (Home and office)
git rm --cache */UserInterfaceState.xcuserstate
git commit -m "Never see you again, UserInterfaceState"

