How to Deploy a Flask App on GitHub: A Complete Guide

Flask is a lightweight Python web framework perfect for building simple web applications and APIs. Once your app is up and running locally, the next logical step is to share your project with othersβ€”and GitHub is the ideal place to do that.

In this blog post, you’ll learn how to deploy a Flask app to GitHub so others can view, clone, and contribute to your project.

πŸ”Ή Note: This guide covers deployment to GitHub (code hosting)β€”not deploying your app to a live server. For that, you can use platforms like Heroku, Vercel, or Render (covered in a separate post).


βœ… Why Deploy to GitHub?

Publishing your Flask app to GitHub allows you to:

  • Showcase your project in a portfolio
  • Collaborate with other developers
  • Use version control for better code management
  • Set up CI/CD pipelines and hosting

🧰 Prerequisites

Before you begin:

  • Python and Flask installed locally
  • A GitHub account
  • Git installed on your machine
  • A functional Flask app

πŸ›  Step-by-Step: Deploying a Flask App to GitHub

1. πŸ“ Organize Your Flask App

Ensure your project has a clean structure, for example:

/my-flask-app
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ templates/
β”‚   └── index.html
β”œβ”€β”€ static/
β”‚   └── style.css
└── README.md
  • app.py: Your main Flask script
  • requirements.txt: Lists Python dependencies
  • README.md: Optional, but recommended for documentation

Run this to generate requirements.txt:

pip freeze > requirements.txt

2. πŸ”§ Initialize Git Locally

Open your terminal and navigate to your project folder:

cd my-flask-app
git init

Then add and commit your files:

git add .
git commit -m "Initial commit of Flask app"

3. 🌐 Create a Repository on GitHub

  1. Go to github.com and click New Repository.
  2. Name it (e.g., my-flask-app) and optionally add a description.
  3. Leave it empty (don’t add README, .gitignore, or licenseβ€”you already have them).
  4. Click Create Repository.

4. πŸ”— Push to GitHub

Once the GitHub repo is created, follow the instructions shown. Typically:

git remote add origin https://github.com/your-username/my-flask-app.git
git branch -M main
git push -u origin main

Now your Flask app is live on GitHub!


πŸ“¦ Optional: Add a .gitignore File

To avoid uploading unnecessary files (like __pycache__ or virtual environments), create a .gitignore file:

__pycache__/
*.pyc
*.pyo
*.pyd
.env
venv/

Commit it:

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

πŸš€ What’s Next?

After publishing your Flask app on GitHub, consider:

  • Adding a README with usage instructions
  • Including screenshots or a live demo link
  • Setting up Heroku, Render, or Fly.io for live deployment
  • Creating GitHub issues and pull requests for collaboration

🧠 Final Thoughts

Deploying a Flask app to GitHub is a great way to organize, share, and grow your project. Whether you’re building a personal portfolio or collaborating with others, GitHub is a valuable tool in your web development workflow.

Sharing Is Caring:

Leave a Comment