64

I'm trying out react native and ejected into a full build environment. Sadly, the eject-script did not create a sensible .gitignore file.

Not knowing a lot about app-development, I wonder what directories I could .gitignore here?

I'm guessing:

  • android/build
  • android/app/build
  • android/.gradle/

Are these alright, or are there any more directories I should .gitignore?

DeX3
  • 5,200
  • 6
  • 44
  • 68

3 Answers3

91

Below is the .gitignore file ships with the react-native init command. You can find the full file here.

# 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/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# node.js
#
node_modules/
package-lock.json # include if you are using npm - don't use both yarn and npm
npm-debug.log
yarn-error.log
yarn.lock # include if you are using yarn - don't use both npm and yarn

# BUCK
buck-out/
\.buckd/
*.keystore

# Fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use Fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle
pbad
  • 55
  • 6
bennygenel
  • 23,896
  • 6
  • 65
  • 78
-1

This is what I am using.

The content should be save in the .gitignore after ios and android envirment like (signature, config file) init,

Then the auto generate file like (index.android.bundle,main.jsbundle) need to be removed using git rm -f ---cached (file path) ,then commit it,then create a new one.

That's becasue the auto generate file don't need to be commited.

node_modules/**/*
.expo/*
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/
package-lock.json
# macOS
.DS_Store
ios/
ios/*
ios/main.jsbundle
ios/**/*
android/
android/*
android/**/*

.vs/
*.log

# 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/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof

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

# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore

# Bundle artifacts
*.jsbundle

# CocoaPods
/ios/Pods/

# Expo
.expo/
web-build/
gogog
  • 410
  • 5
  • 9
  • 1
    you are ignoring all files inside `android/`? and why ignoring the `package-lock.json`? that seems wrong. – caesarsol Dec 06 '22 at 14:47
  • @caesarsol because the android file is somewhat unchanged, It's all about config files for different phones. Next, package-lock.json should not be ignored , but it's an auto generated file, or it all depends on your like, I am not sure. – gogog Dec 16 '22 at 03:14
  • yes but you will ignore all future changes in that directory, and that is probably not what you want... about the `package-lock.json`, it [should be absolutely committed](https://docs.npmjs.com/cli/v7/configuring-npm/package-lock-json#description) :) – caesarsol Dec 30 '22 at 16:13
-3

This is the newer version of .gitignore for react-native projects https://github.com/facebook/react-native/blob/master/.gitignore

Adding package manager lock file is optional. You can add them by adding package-lock.json for npm or yarn.lock for yarn, at the end of the below code.

# Xcode
!**/*.xcodeproj
!**/*.pbxproj
!**/*.xcworkspacedata
!**/*.xcsettings
!**/*.xcscheme
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Gradle
/build/
/RNTester/android/app/build/
/RNTester/android/app/gradle/
/RNTester/android/app/gradlew
/RNTester/android/app/gradlew.bat
/ReactAndroid/build/

# Buck
.buckd
buck-out
/ReactAndroid/src/main/jni/prebuilt/lib/armeabi-v7a/
/ReactAndroid/src/main/jni/prebuilt/lib/x86/
/ReactAndroid/src/main/gen

# Watchman
.watchmanconfig

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

# Node
node_modules
*.log
.nvm
/bots/node_modules/
package-lock.json

# OS X
.DS_Store

# Test generated files
/ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
*.js.meta

/coverage
/third-party

# Root dir shouldn't have Xcode project
/*.xcodeproj

# ReactCommon subdir shouldn't have Xcode project
/ReactCommon/**/*.xcodeproj
RNTester/build

# Libs that shouldn't have Xcode project
/Libraries/FBLazyVector/**/*.xcodeproj
/Libraries/FBReactNativeSpec/**/*.xcodeproj
/Libraries/RCTRequired/**/*.xcodeproj
/React/CoreModules/**/*.xcodeproj
/packages/react-native-codegen/**/*.xcodeproj

# CocoaPods
/template/ios/Pods/
/template/ios/Podfile.lock
/RNTester/Gemfile.lock

# Ignore RNTester specific Pods, but keep the __offline_mirrors__ here.
RNTester/Pods/*
!RNTester/Pods/__offline_mirrors

# react-native-codegen
/ReactCommon/fabric/components/rncore/
/schema-rncore.json
Iman Kermani
  • 919
  • 9
  • 14
  • 2
    This is the actual react-native repositories gitignore. See the accepted answer's link for an example template for react native projects. – blub Oct 16 '19 at 11:22