Setup Git for a Flutter Project with Firebase inside a Public Repo

Setup Git for a Flutter Project with Firebase inside a Public Repo

As a developer, maintaining a public repository for your Flutter project can be a great way to share your work with community and get feedback and contributions from others.

But we want to ensure that sensitive data such as :

  • Firebase configuration files

  • API keys

  • Authentication tokens

  • Database Credentials

  • Storage Credentials

So let's see the process to do that.

Step 1: Initial Flutter Project with Firebase

Go ahead and create a Flutter project and connect it to Firebase. For a step by step description. Read the following article on connecting your Flutter project to your Firebase

I am creating an open source app that I want to use for my own car maintenance. As you can see I am supporting all the platforms.

Finally My App has been connected to Firebase:

Step 2: Setup Git and .gitignore

To start, you'll need to create a new Git repository for your Flutter project.You can do this by opening a terminal or command prompt and navigating to the root directory of your project. Then, run the following command to initialize a new Git repository:

git init

Once git has been initialized. We need to check if .gitignore file has been created.

Replace Default .gitignore

Since our .gitignore files has been created. Let's go ahead and modify it to ignore sensitive files.

This is our initial .gitignore :

# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

Go ahead and replace it with the one available in the following gist:

https://gist.github.com/khkred/54baf727b3ac8f9a2210812d88250ba7

After replacement this is my final gist:

# Do not remove or rename entries in this file, only add new ones
# See https://github.com/flutter/flutter/issues/128635 for more context.

# Miscellaneous
*.class
*.lock
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.classpath
.project
.settings/
.vscode/*

# Flutter repo-specific
/bin/cache/
/bin/internal/bootstrap.bat
/bin/internal/bootstrap.sh
/bin/mingit/
/dev/benchmarks/mega_gallery/
/dev/bots/.recipe_deps
/dev/bots/android_tools/
/dev/devicelab/ABresults*.json
/dev/docs/doc/
/dev/docs/api_docs.zip
/dev/docs/flutter.docs.zip
/dev/docs/lib/
/dev/docs/pubspec.yaml
/dev/integration_tests/**/xcuserdata
/dev/integration_tests/**/Pods
/packages/flutter/coverage/
version
analysis_benchmark.json

# packages file containing multi-root paths
.packages.generated

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
**/generated_plugin_registrant.dart
.packages
.pub-preload-cache/
.pub-cache/
.pub/
build/
flutter_*.png
linked_*.ds
unlinked.ds
unlinked_spec.ds

# Android related
**/android/**/gradle-wrapper.jar
.gradle/
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
**/android/key.properties
*.jks
 # Firebase config file for Android
**/android/google-services.json 

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/.last_build_id
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/ephemeral
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Firebase config file
**/ios/GoogleService-Info.plist  

# macOS
**/Flutter/ephemeral/
**/Pods/
**/macos/Flutter/GeneratedPluginRegistrant.swift
**/macos/Flutter/ephemeral
# Firebase config file for MAC OS
**/macos/Runner/GoogleService-Info.plist  
**/xcuserdata/

# Firebase Configuration
/lib/firebase_options.dart

# Windows
**/windows/flutter/generated_plugin_registrant.cc
**/windows/flutter/generated_plugin_registrant.h
**/windows/flutter/generated_plugins.cmake
# Firebase config file for Windows
**/windows/google-services.json  

# Linux
**/linux/flutter/generated_plugin_registrant.cc
**/linux/flutter/generated_plugin_registrant.h
**/linux/flutter/generated_plugins.cmake

# Web
**/web/keys.json  # Example sensitive data for web

# Coverage
coverage/

# Symbols
app.*.symbols

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
!/dev/ci/**/Gemfile.lock
!.vscode/settings.json

Setup files into our git step by step

The first thing we want to do is add our .gitignore as this would let git know which files it'll have to ignore once we commit

git add .gitignore
git commit -m "Add initial .gitignore"

Next, you'll need to add your Flutter project files to the Git repository. You can do this by running the following command:

git add .

Once you've added your files to the repository, you'll need to commit them. To do this, run the following command:

git commit -m "Initial commit"

This will create a new commit with a meaningful commit message.

Step 3: Publish your initial app on Github:

Through Android Studio:

If you are using Android Studio. You can share it immediately using the following command:

Through Github:

Create a new public repo in Github:

Finally you can connect your local repo to Github with the following command:

git remote add origin git@github.com:khkred/kaida.git
git branch -M main
git push -u origin main

Make sure to replace git remote add origin git@github.com:khkred/kaida.git with your own public repo.

There you go you finally have a public repo with all of the gitignore files added.

Did you find this article valuable?

Support Harish Kunchala by becoming a sponsor. Any amount is appreciated!