Push Code to GitHub

This tutorial explains how to upload your local project to GitHub.

GitHub is a platform where developers store and manage their code using Git, a version control system that tracks changes in files.

Uploading your project to GitHub helps you: - Backup your code online - Track changes - Share projects with others


Step 1 - Open Terminal

Open your terminal (Command Prompt, PowerShell, or Terminal) and go to your project folder.

Example:

cd project_folder

What this command does

cd means change directory.
It moves the terminal into the folder where your project files are located.


Step 2 - Initialize Git Repository

Run:

git init

What this command does

git init creates a Git repository in your project folder.
Git will now start tracking changes in your files.

It also creates a hidden folder called:

.git

This folder stores the version history of your project.


Step 3 - Check Repository Status

Run:

git status

What this command does

Shows the current status of your project.

It tells you: - which files are new - which files are modified - which files are ready to commit


Step 4 - Add Files to Git

Run:

git add .

What this command does

Adds files to the staging area.

The dot . means add all files in the current folder.

These files are now prepared for the next commit.


Step 5 - Commit the Files

Run:

git commit -m "first commit"

What this command does

git commit saves a snapshot of your project.

-m allows you to add a message describing the change.

Example messages: - first commit - add login page - fix navbar bug


Step 6 - Create GitHub Repository

Go to https://github.com

Click New Repository and create a repository.

After creating it, GitHub will show a repository URL like this: - https://github.com/username/project.git


Step 7 - Connect Local Project to GitHub

Run:

git remote add origin https://github.com/username/project.git

What this command does

Connects your local project to the GitHub repository.

  • origin → name of the remote repository
  • URL → GitHub repository address

Step 8 - Push Code to GitHub

Run:

git push origin main

What this command does

Uploads your local commits to GitHub.

  • git push → send code to remote repository
  • origin → remote repository name
  • main → branch name

After running this command, your project will appear on GitHub.


Summary of Commands

Command Purpose
cd folder Move into project directory
git init Initialize Git repository
git status Show repository status
git add . Add files to staging area
git commit -m "message" Save changes
git remote add origin URL Connect project to GitHub
git push origin main Upload code to GitHub

Your project is now successfully stored on GitHub.