I want git to ignore my UserInterfaceState.xcuserstate
file in my XCode4 project, but where should I put the .gitignore
file?, is it inside the .git
folder? or out? The .git
is in same folder with the ProjectName.xcodeproj
file
For a . gitignore file, you should place it in the root folder of the repository.
A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .
Yes, you can track the . gitignore file, but you do not have to. The main reason of having this file into repository is to have everyone working on the project, ignoring same files and folders. Also see this: Should you commit .
You can have a .gitignore
in every single directory of your project.
However, the best practice is to have one single .gitignore
file on the project root directory, and place all files that you want to ignore in it, like this:
ignoredFile.whatever ignoredDirectory/* directory/ignoredFileInsideDirectory .svn
Once you create the .gitignore
file, the ignore files that have changes or are new into the repository will not be shown to as waiting for commit.
You can also have one global local git ignore file, that will manage all of your git repositories.
git config --global core.excludesfile ~/.gitignore_global
This alternative is particularly interesting for ignored files that are non-project related, such as IDE related files and so on.
There are there approaches to ignore files in git:
~/.gitignore_global
path. This approach good if you want to exclude some type files which is generated by OS or any other logging, cashing and etc. tools. .git/info/exclude
file in your repository. The rules specified under this file will not be committed, which means it will not be shared with others. Generally this approach useful to prevent committing of locally generated files. For example, for files created by your editor. .gitignore
in any sub path of your specific repository. This approach usually used to ignore some types of file only under specific folder of specific repository. While this files can be added to version controlling by other paths and other repositories. So, My suggest to you is, if you want to ignore your specific file (UserInterfaceState.xcuserstate
) in your all repositories the best approach is to use global git ignore approach. However if your file is generated only in specific repository you can use per-repository git ignore approach.
For more information you can read this great blog post. And there per language specific git ignore rules can be founded here. And you can auto generate general git ignore rules for specific language, tool or os using this web site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With