DevOps & Git

How to Upload and Deploy Projects on GitHub Successfully (With Common Issues & Fixes)

Himanshu Pal

Himanshu Pal

How to Upload and Deploy Projects on GitHub Successfully (With Common Issues & Fixes)

1. Introduction

GitHub isn’t just a storage place for code—it’s the backbone of modern software development.
From version control and open-source contributions to team collaboration and deployment, GitHub is the developer’s command center.

If you’ve ever tried pushing your first project and got errors like “fatal: remote origin already exists” or “authentication failed”, this guide is for you.

In this blog, you’ll learn:

  • How to upload your project step by step.

  • How to deploy your project (static or dynamic).

  • How to solve the most common Git/GitHub issues.


2. Prerequisites

Before starting, ensure you have the following:

Git Installed → Run in terminal:

git --version

GitHub AccountSign up here.

Project Files Ready → Your local project folder.

Checklist:

  • Git installed

  • GitHub account created

  • Project files ready


3. Step 1: Initialize Git in Your Project

Navigate to your project folder:

cd path/to/your/project

Run the following commands:

git init
git add .
git commit -m "Initial commit"

Command Breakdown:

  • git init → Creates a new local repository inside your project.

  • git add . → Stages all files in the current directory.

  • git commit -m "Initial commit" → Saves a snapshot of your code with a commit message.


4. Step 2: Create a Repository on GitHub

  1. Go to GitHub Repositories.

  2. Click New Repository.

  3. Enter:

    • Repository name (e.g., my-first-project).

    • Optional description.

    • Visibility → Public or Private.

  4. Uncheck “Initialize with README” if you already committed locally.

Click Create Repository.


Now connect your local repo to GitHub:

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

Explanation:

  • git remote add origin <URL> → Links your local repo to the GitHub repo.

  • git branch -M main → Renames your default branch to main.

  • git push -u origin main → Uploads your project to GitHub.


6. Step 4: Deploy Projects from GitHub

Option A: Deploy Static Sites (GitHub Pages)

  1. Go to Repo → Settings → Pages.

  2. Under Source, select:

    • Branch: main

    • Folder: / (root)

  3. Save.

  4. Access your project at:

    https://username.github.io/repo-name/

Option B: Deploy Dynamic Apps (Using GitHub Actions)

If you’re deploying Node.js, Python, or React apps, GitHub Actions can automate builds & deployments.

Example: Node.js Workflow (.github/workflows/deploy.yml)

name: Node.js CI/CD

on:
  push:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js
      uses: actions/setup-node@v3
      with:
        node-version: '18'
    - run: npm install
    - run: npm run build
    - run: npm test

This runs automatically every time you push code to main.


7. Common Issues & Their Solutions

🔹 Error 1: fatal: remote origin already exists

Cause: You already linked a remote.

Fix:

git remote remove origin
git remote add origin https://github.com/username/repo.git

🔹 Error 2: failed to push some refs

Cause: Branch mismatch between local and remote.

Fix:

git pull origin main --rebase
git push origin main

🔹 Error 3: Authentication Failed (Token Issue)

Cause: GitHub removed password-based authentication.

Fix: Use Personal Access Token (PAT).

  1. Go to GitHub → Settings → Developer Settings → Tokens.

  2. Generate a token with repo permissions.

  3. Push with token:

git push https://<TOKEN>@github.com/username/repo.git

🔹 Error 4: Large File Size Error

Cause: GitHub blocks files >100MB.

Fix: Use Git LFS (Large File Storage).

git lfs install
git lfs track "*.mp4"
git add .gitattributes
git add .
git commit -m "Add large file support"
git push origin main

8. Best Practices

  • ✅ Add .gitignore to exclude unwanted files (e.g., node_modules, .env, dist/).

  • ✅ Write clear commit messages:

    git commit -m "Fix: updated login form validation"
  • ✅ Use branches:

    • feature/signup

    • bugfix/navbar

  • ✅ Always add a README.md → explain setup & usage.


9. Interactive Section: Hands-On Mini Task

Try this yourself:

  1. Create a sample project (hello-world).

  2. Upload it to GitHub following the steps above.

  3. Deploy with GitHub Pages.

  4. Share your repo link in the comments!


10. Conclusion

Summary:

  • Initialize Git → Create Repo → Link → Push → Deploy → Troubleshoot.

  • Common issues like remote errors, auth failures, and large files can be fixed easily.

Drop your GitHub profile link in the comments so others can connect!