Skip to content

How to put your Python project on GitHub

This guide walks through the one-time setup to get a uv-based Python project into a Git repository and pushed to GitHub. It assumes the project already exists on your machine (see Create your first Python project if it doesn’t).

For background on what Git and GitHub are, see Enough Git to Supervise Your AI Coding Agent.

Install Git

macOS includes Git with the Xcode command-line tools. Install them if you haven’t already:

xcode-select --install

On Linux, use your package manager:

# Debian/Ubuntu
sudo apt install git

# Fedora
sudo dnf install git

Verify the installation:

$ git --version
git version 2.47.0

Configure Git

Git labels every commit with your name and email. Set these once:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Use the same email associated with your GitHub account so that commits are linked to your profile.

Initialize the repository

Open a terminal in your project directory and run:

git init

This creates a hidden .git folder that tracks your project’s history. The folder itself doesn’t change how your project works.

Review .gitignore

If the project was created with uv init, a .gitignore file already exists. Verify it includes entries for files that shouldn’t be tracked:

# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# Virtual environments
.venv

Important

Never commit secrets like API keys, .env files, or credentials. Add them to .gitignore before your first commit.

Make your first commit

Stage all files and create the first commit:

git add .
git commit -m "Initial commit"

git add . stages every file not excluded by .gitignore. git commit saves the snapshot. For more on what staging and committing mean, see the four states of your code.

Create a GitHub repository

  1. Go to github.com/new
  2. Enter a repository name (typically matching your project folder name)
  3. Choose public or private visibility
  4. Do not check “Add a README file” or any other initialization options (your project already has files)
  5. Click Create repository

GitHub will show a page with setup instructions. You need the repository URL, which looks like https://github.com/your-username/your-project.git.

Connect and push

Link your local repository to GitHub and push:

git remote add origin https://github.com/your-username/your-project.git
git push -u origin main

GitHub may prompt for authentication. If you haven’t authenticated before, follow GitHub’s instructions for setting up a personal access token or use the GitHub CLI (gh auth login).

Verify on GitHub

Open your repository’s URL in a browser. Your project files should be visible, along with the commit message “Initial commit.”

From here, your project is backed up on GitHub and ready for features that depend on it, like GitHub Actions or pre-commit hooks.

Get Python tooling updates

Subscribe to the newsletter
Last updated on

Please submit corrections and feedback...