← Back to Articles         
Push code from Console

Push code from Console

Published on 08 Oct 2026     3 min read Git & GitHub
Git Fundamentals
 

Git Commands to Push Local Code to GitHub — Step by Step

Example:

  • Local Project: D:\Syed\GitTest\ConsoleApp3

  • GitHub Repository: https://github.com/syedmohamed2008/repo_test3.git

  • Branch: main

Step 1: Navigate to the project folder

cd D:\Syed\GitTest\ConsoleApp3

Moves to your local project directory.

Step 2: Initialize Git (first time only)

git init

Creates a local Git repository (.git folder). Skip this if Git is already initialized.

Step 3: Connect to GitHub (first time only)

git remote add origin https://github.com/syedmohamed2008/repo_test3.git

Connects your local repository to the existing GitHub repository.

Verify:

git remote -v

Skip adding the remote if origin is already configured correctly.

Step 4: Check the current branch

git branch

Displays your local branches. The * indicates the current branch.

Example:

* main

Step 5: Check modified files

git status

Displays new, modified, deleted, and staged files.

Step 6: Stage your changes

git add .

Stages all changes under the current directory.

Alternatively, stage a specific file:

git add Program.cs

Step 7: Commit your changes

git commit -m "Updated ConsoleApp3 application"

Creates a commit in your local Git repository.

Step 8: Pull the latest code

git pull --rebase origin main

Downloads the latest remote changes and replays your local commits on top of them.

Note: Use this when your local and remote branches share Git history. If Git reports unrelated histories or merge conflicts, resolve those before pushing.

Step 9: Push code to GitHub

git push -u origin main

Uploads your local commits to GitHub.

  • origin — Remote repository.

  • main — Target branch.

  • -u — Sets upstream tracking for future pushes.

After setting upstream, you can simply use:

git push

Step 10: Verify the result

git status

Expected output:

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
 

Daily Git Workflow — Most Important

Once the repository is configured, these are the commands you will commonly use:

# 1. Navigate to project
cd D:\Syed\GitTest\ConsoleApp3

# 2. Check modified files
git status

# 3. Stage changes
git add .

# 4. Commit changes
git commit -m "Updated application code"

# 5. Get latest remote changes
git pull --rebase origin main

# 6. Push changes to GitHub
git push origin main

# 7. Verify status
git status

Git Commands — Quick Reference

Command

Purpose

git init

Initialize a local repository

git remote add origin URL

Connect to a remote repository

git remote -v

View remote repositories

git branch

Check current branch

git status

Check changed files

git add .

Stage all changes

git commit -m "message"

Commit changes locally

git pull --rebase origin main

Integrate latest remote changes

git push -u origin main

First push with upstream tracking

git push

Push subsequent commits

git log --oneline -5

View the latest five commits

Remember the Git workflow:

Working Directory

Staging Area

Local Repository

git add

→

git commit

→

git push

 

GitHub Remote Repository

Key point for interviews: git commit saves changes locally, while git push uploads committed changes to the remote repository.

← Back to Articles