Push Local Project to GitHub - Complete Guide

Created: 2025-05-25 14:02:37 | Last updated: 2025-05-25 14:03:31 | Status: Public

This guide walks you through pushing an existing local project from VS Code to GitHub.

Prerequisites

  • VS Code with your local project
  • GitHub account
  • Git installed on your computer

Step 1: Create .gitignore File

Before committing, create a .gitignore file to avoid pushing unnecessary files.

Create the file:

Windows (Command Prompt/PowerShell):

echo. > .gitignore

Windows (PowerShell alternative):

New-Item .gitignore -ItemType File

Mac/Linux:

touch .gitignore

Or simply create the file in VS Code: File → New File → Save as .gitignore

Add these common ignores for Python projects:

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
venv/
env/
ENV/

# IDE
.vscode/
.idea/

# Misc
.DS_Store

Step 2: Create Repository on GitHub

  1. Go to github.com and sign in
  2. Click the “+” button in the top right corner
  3. Select “New repository”
  4. Name your repository
  5. Important: Don’t initialize with README, .gitignore, or license (keep it empty)
  6. Click “Create repository”

GitHub will show you commands to use - you can reference those too.

Step 3: Initialize Git and Push to GitHub

Run these commands in your project directory:

Initialize Git (if not already done)

git init

Configure Git (first time setup)

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

Stage and commit your files

git add .
git commit -m "Initial commit"

Connect to GitHub and push

Replace username and repository with your actual GitHub username and repo name:

git remote add origin https://github.com/username/repository.git
git branch -M main
git push -u origin main

Authentication

GitHub requires authentication. You’ll need to set up:
- Personal Access Token (recommended)
- SSH keys
- GitHub CLI

Follow GitHub’s authentication guide if prompted during the push.

Troubleshooting

If you already committed files you want to ignore:

git rm --cached filename
git commit -m "Remove ignored files"

If you get authentication errors:
- Check your GitHub credentials
- Consider using GitHub CLI or SSH keys
- Verify your personal access token

Next Steps

After your initial push:
- Future changes: git add .git commit -m "message"git push
- Create branches for features
- Set up pull requests for collaboration


This guide covers the basic workflow. Refer to Git and GitHub documentation for advanced features.