64

I'm playing with Facebook/React Native, and when I run git init, I have no idea what should be ignored expect node_modules folder,

Should I commit all iOS folder?

Thanks

Jon Miles
  • 9,605
  • 11
  • 46
  • 66
Yuan He
  • 1,143
  • 1
  • 12
  • 14

6 Answers6

37

React Native CLI creates a .gitignore file when you start a new project:

react-native init <ProjectName>

It covers all the basics that should/can be ignored.

Source: https://github.com/facebook/react-native/blob/master/template/_gitignore

designorant
  • 2,344
  • 14
  • 25
13

gitignore.io suggests the following .gitignore file for react-native:

Created by https://www.gitignore.io/api/reactnative

### ReactNative ###
# React Native Stack Base
### ReactNative.Xcode Stack ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

### ReactNative.Node Stack ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### ReactNative.Buck Stack ###
buck-out/
.buckconfig.local
.buckd/
.buckversion
.fakebuckversion

### ReactNative.macOS Stack ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### ReactNative.Gradle Stack ###
.gradle
**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### ReactNative.Android Stack ###
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Freeline
freeline.py
freeline/
freeline_project_description.json

### ReactNative.Linux Stack ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# End of https://www.gitignore.io/api/reactnative
Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104
9

We suggest this .gitignore: react-native/Examples/SampleApp/.gitignore.

It ignores both user-specific Xcode files and the node_modules dir.

Edgar
  • 6,022
  • 8
  • 33
  • 66
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
  • This is a good start but doesn't include what is needed for android. The .gitignore that the cli generates is complete with both ios and android. – Tony Dec 15 '16 at 16:08
  • 2
    Link is dead (which is one reason we don't like link-only answers :) – Dave Newton Jun 02 '18 at 20:05
3

This is a related question:What should Xcode 6 gitignore file include?

It can be divided into three categories:

  1. IDE(Webstorm,Xcode) config file,like:.idea/,ios/ProjectName.xcodeproj/xcuserdata
  2. version control tools(git,svn) file, like: .git
  3. other files,for example,.DS_Store is OSX dir config file

my answer is which have been inspected in practice:

### SVN template
.svn/
### Xcode template
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml

# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# Gradle:
.idea/gradle.xml
.idea/libraries
.idea

# Mongo Explorer plugin:
.idea/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### TortoiseGit template
# Project-level settings
/.tgitconfig

*.swp

# node_modules/,Xcode and Webstorm will spend lots of time for indexing this dir
node_modules/

# ios/Pods,
ios/Pods/

# OS X temporary files that should never be committed
.DS_Store
src/components/.DS_Store

# user personal info,for example debug info
ios/ProjectName.xcodeproj/project.xcworkspace/
ios/ProjectName.xcodeproj/xcuserdata

# Podfile versions
ios/Podfile.lock

# Created by .ignore support plugin (hsz.mobi)

Hope it helps you!

Community
  • 1
  • 1
bocai
  • 437
  • 2
  • 9
1

It's probably worth noting that react-native init <project-name> generates a .gitignore file for you. This will likely be up to date with React Native's current tooling and build outputs. So this should be a good starting point.

Using react-native-cli 1.0.0 and react-native 0.36.0 generated the following .gitignore file:

# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IJ
#
*.iml
.idea
.gradle
local.properties

# node.js
#
node_modules/
npm-debug.log

# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore
Barjavel
  • 1,626
  • 3
  • 19
  • 31
-2

If you look at the React Native examples:

https://github.com/facebook/react-native/tree/master/Examples

Each one has a directory with a contents similar to the iOS directory generated by react-native-cli. Looking further into the Xcode project file, it's referenced in there too, and look at the contents - there's things like the launch screen.

So yes, the iOS directory is needed.

Regarding node_modules, I suggest you look at this answer which provides more information:

https://stackoverflow.com/a/19416403/125680

Community
  • 1
  • 1
Colin Ramsay
  • 16,086
  • 9
  • 52
  • 57
  • I think IOS and Android directories is not required. if you already use a react-native command line to generate your react-native application, you can use .... react-native eject .... To rebuild the IOS and Android native files. that will make your project smaller in GitHub repo, let the other contributors clone your project easily and make them use their settings with IOS Xcode Project. – Ahmed Ashraf Mar 30 '17 at 11:22
  • I know this is an old thread, but I disagree with this. Once you change things in Info.plist for example, you will run into trouble using your method. Maybe you don't change this file, but most people will. (Imagine using HTTP, not HTTPS which you have to enable in this file) – finngu Dec 07 '17 at 16:53
  • 1
    No doubt we need `/ios` and `/android` directories. How about `ios/build`? Do we `.gitignore` it? – Green Jun 19 '18 at 06:30
  • Note that the `eject` command has recently been removed from `react-native`. – Phantom Watson Aug 20 '19 at 16:32