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

# IntelliJ related

# 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.

# Flutter/Dart/Pub related

# Symbolication related

# Obfuscation related

# Android Studio will place build artifacts here

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

After replacement this is my final gist:

# Do not remove or rename entries in this file, only add new ones
# See for more context.

# Miscellaneous

# IntelliJ related

# Visual Studio Code related

# Flutter repo-specific

# packages file containing multi-root paths

# Flutter/Dart/Pub related

# Android related
 # Firebase config file for Android

# iOS/XCode related
# Firebase config file

# macOS
# Firebase config file for MAC OS

# Firebase Configuration

# Windows
# Firebase config file for Windows

# Linux

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

# Coverage

# Symbols

# Exceptions to above rules.

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 branch -M main
git push -u origin main

Make sure to replace git remote add origin 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!