.gitignore for PhoneGap/Cordova 3.0 projects - what should I commit?

Expanding on @Jake Moshenko answer:

I like the idea of omitting the platforms directory. In fact, I am am able to exclude both the plugins and platforms directories. A good starting point for the .gitignore:

platforms/
plugins/

The problem with this is that clean copy of the repo must be initialized before you can actually work with it. It may make sense to create an init script such as:

#!/bin/bash
textReset=$(tput sgr0)
textGreen=$(tput setaf 2)
message_info () {
  echo "${textGreen}[my-app]${textReset} $1"
}

message_info "Creating necessary directories..."
mkdir plugins
mkdir platforms

message_info "Adding platforms..."
# If using cordova, change to: cordova platform add android
phonegap build android
phonegap build ios

message_info "Adding plugins..."
# If using cordova, change to: cordova plugin add
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

A caveat to this approach is that it makes it a little more challenging to customize the platform specific app code/config outside of what's supported by phonegap/cordova (i.e. screen orientation support).

Update: Bash Gist

This gist contains a more complete script for handling a project that does not commit the plugins and platforms directories. It provides a mechanism for copying the icons and splashscreen images from www to the platform directories (for iOS and Android), installing plugins, and handling platform specific files that should be added to version control.

Update: Grunt Gist

Here is another gist which is a Grunt port of the above mentioned bash script. (Thanks to @obie for suggesting grunt).


The answer depends on wich platforms you're developing the phongap app, and if you're following the standard directory structure.

If your project directory structure is standard, then you can start from this gitignore and modify it for your needs.

On a rule of thumb you've to exclude all generated files like the bin/ and gen/ directories. If you're developing an Android version of your app you should exclude build files too like *.apk.

All generated files in the android subdirectory should be excluded too:

Android/bin/
Android/gen/
Android/assets/

So I just figured this out through trial and error. The platforms directory can be omitted if you are using phonegap local or remote build, as it is generated on the fly. All of the other folders, including the hidden folder .cordova are required.