Top gitignore Questions

List of Tags
354
trobrock

I have an already initialized git repo that I added a .gitignore file to, how can I refresh the file index so the files I want ignored get ignored?

Answered By: trobrock ( 572)

Just got the answer from the IRC channel.

First, commit any outstanding code changes, and then, run this command:

git rm -r --cached .

This removes everything from the index, then just run:

git add .

Commit it:

git commit -m ".gitignore is now working"
317
Jacques René Mesrine

I just did a git init on the root of my new project.

Then I created a .gitignore file.

Now, when I type "git status", ".gitignore" appears in the list of untracked files. Why is that?

Answered By: August Lilleaas ( 312)

The .gitignore file should be in your repository, so it should indeed be added and committed in, as "git status" suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on.

So, add it to your repository, it should not be gitignored.

That being said, if you really want you can add .gitignore to the .gitignore file if you don't want it to be committed.

Which files should I include in .gitignore when using Git in conjunction with Xcode?

Answered By: Adam ( 129)

UPDATE 2013: the syntax for .gitignore is very hard to understand (badly implemented IMHO), and my last update didn't do as intended. I've updated it with something that APPEARS to do as intended

UPDATE: gist on github too, as requested: https://gist.github.com/3786883


I was previously using the top-voted answer, but it needs a bit of cleanup, so here it is re-done for Xcode 4, with some improvements.

I've also added some notes inline - I think it's risky to have files in a .gitignore if you don't explain why they're there :). Read the notes, if I've got anything wrong, please shout, and I'll re-research / modify / fix...

I've researched every file in this list, but several of them do not exist in Apple's official xcode docs (google couldn't find them, Developer.apple.com couldn't find them), so I had to go on mailing lists and heresay.

#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
# and you should use a different .gitignore (or none at all)
# This file is for SOURCE projects, where there are many extra
# files that we want to exclude
#
#########################

#####
# OS X temporary files that should never be committed

.DS_Store
*.swp
*.lock
profile


####
# Xcode temporary files that should never be committed
# 
# NB: NIB/XIB files still exist even on Storyboard projects, so we want this...

*~.nib


####
# Xcode build files -
#
# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData"

DerivedData/

# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build"

build/


#####
# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups)
#
# This is complicated:
#
# SOMETIMES you need to put this file in version control.
# Apple designed it poorly - if you use "custom executables", they are
#  saved in this file.
# 99% of projects do NOT use those, so they do NOT want to version control this file.
#  ..but if you're in the 1%, comment out the line "*.pbxuser"

*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
#    NB: also, whitelist the default ones, some projects need to use these
!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3


####
# Xcode 4 - semi-personal settings
#
#
# OPTION 1: ---------------------------------
#     throw away ALL personal settings (including custom schemes!
#     - unless they are "shared")
#
# NB: this is exclusive with OPTION 2 below
xcuserdata

# OPTION 2: ---------------------------------
#     get rid of ALL personal settings, but KEEP SOME OF THEM
#     - NB: you must manually uncomment the bits you want to keep
#
# NB: this is exclusive with OPTION 1 above
#
#xcuserdata/**/*

#     (requires option 2 above): Personal Schemes
#
#!xcuserdata/**/xcschemes/*

####
# XCode 4 workspaces - more detailed
#
# Workspaces are important! They are a core feature of Xcode - don't exclude them :)
#
# Workspace layout is quite spammy. For reference:
#
# /(root)/
#   /(project-name).xcodeproj/
#     project.pbxproj
#     /project.xcworkspace/
#       contents.xcworkspacedata
#       /xcuserdata/
#         /(your name)/xcuserdatad/
#           UserInterfaceState.xcuserstate
#     /xcsshareddata/
#       /xcschemes/
#         (shared scheme name).xcscheme
#     /xcuserdata/
#       /(your name)/xcuserdatad/
#         (private scheme).xcscheme
#         xcschememanagement.plist
#
#

####
# Xcode 4 - Deprecated classes
#
# Allegedly, if you manually "deprecate" your classes, they get moved here.
#
# We're using source-control, so this is a "feature" that we do not want!

*.moved-aside

####
# Cocoapods: cocoapods.org
# 
# Ignoring these files means that whoever uses the code will first have to run:
# pod install
# in the App.xcodeproj directory.
# This ensures the latest dependencies are used.
Pods/
Podfile.lock


####
# UNKNOWN: recommended by others, but I can't discover what these files are
#
# ...none. Everything is now explained.

Which files should I include in .gitignore when using Git in conjunction with Visual Studio Solutions (.sln) and Projects?

Community Wiki:

#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.unsuccessfulbuild
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

#MonoDevelop
*.pidb
*.userprefs

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
*.sass-cache

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

#NuGet
packages/

#ncrunch
*ncrunch*
*crunch*.local.xml

# visual studio database projects
*.dbmdl

#Test files
*.testsettings
Answered By: Lachlan Roche ( 65)

I use the following .gitignore for C# projects. Additional patterns are added as and when they are needed.

[Oo]bj
[Bb]in
*.user
*.suo
*.[Cc]ache
*.bak
*.ncb
*.log 
*.DS_Store
[Tt]humbs.db 
_ReSharper.*
*.resharper
Ankh.NoLoad
157
Ben Hymers

I have a directory structure like this:

.git/
.gitignore
main/
  ...
tools/
  ...
...

Inside main and tools, and any other directory, at any level, there can be a 'bin' directory, which I want to ignore (and I want to ignore everything under it too). I've tried each of these patterns in .gitignore but none of them work:

/**/bin/**/*
/./**/bin/**/*
./**/bin/**/*
**/bin/**/*
*/bin/**/*
bin/**/*
/**/bin/* #and the others with just * at the end too

Can anyone help me out? The first pattern (the one I think should be working) works just fine if I do this:

/main/**/bin/**/*

But I don't want to have an entry for every top-level directory and I don't want to have to modify .gitignore every time I add a new one.

This is on Windows using the latest msysgit.

EDIT: one more thing, there are files and directories that have the substring 'bin' in their names, I don't want those to be ignored :)

Answered By: Charles Bailey ( 269)

I've no idea where the impression that ** has any special meaning in a .gitignore pattern comes from. It's not mentioned in the gitignore man page or the fnmatch man page which the gitignore man page refers to.

The way to ignore all directories called bin anywhere below the current level in a directory tree is with a .gitignore file with the pattern:

bin/

This should be pretty clear from the gitignore man page. There's even an example of ignoring a directory called foo using an analogous pattern.