Push Code to GitHub from PowerShell
Complete tutorial with real terminal output & error handling
Git push rejected? Merge conflicts? If you’ve hit these walls, you’re not alone. In this guide, I’ll walk you through pushing code to GitHub using PowerShell with real terminal output, so you know exactly what success looks like.
GitHub is the industry standard for version control. Whether you’re building a personal project or collaborating with a team, knowing how to push code from your local machine to GitHub is essential. I’m using a real project called Google News Agent ,a Python CLI application that fetches news from Google News RSS feeds. You’ll see the actual PowerShell commands and outputs exactly as they appeared when pushing this project to GitHub.
What You’ll Need
· Git installed on Windows, Mac, or Linux
· A GitHub account
· A repository created on GitHub
· Your repository cloned to your local machine
The Complete Git Workflow in 6 Steps
Here’s the workflow we’ll follow. Each step has actual PowerShell output so you can see exactly what to expect on your machine.
Step 1: Configure Git with Your Credentials
Open PowerShell and tell Git who you are:
git config — global user.name “yourname”
git config — global user.email “yourname@gmail.com”
Replace the name and email with your actual values. This identifies who made the commits in your repository history.
Step 2: Navigate to Your Repository Directory
Use the cd command to navigate to your project folder:
cd C:\Users\your-username\google-news-agent
Replace your-username with your actual Windows username (or navigate to the folder using Windows Explorer and copy the path)
Make sure you’re in the root directory of your repository. This is where the .git folder is located.
Step 3: Check the Status of Your Changes
Before making changes, check what files have been modified:
git status
This command shows untracked files (new files) and modified files. These are the files Git is ready to process.
Step 4: Stage Your Changes
Add all your files to the staging area:
git add .
The dot (.) means “add all files”. This prepares your files for the commit. It’s like putting items in a shopping cart before checkout.
Step 5: Commit Your Changes
Create a commit with a descriptive message:
git commit -m “feat: Add Google News Agent-Python CLI for fetching news”
The -m flag adds a message. Good commit messages describe what changed. Examples: feat: Add search, fix: Handle URL encoding, docs: Update README.
Expected output:
[main d525b02] feat: Add Google News Agent
3 files changed, 650 insertions(+), 2 deletions(-)
create mode 100644 google_news_agent.py
create mode 100644 requirements.txt
Step 6: Push to GitHub
Upload your commits to GitHub:
git push origin main
This uploads your commits to the “main” branch on “origin” (GitHub). After this command succeeds, your code is live on GitHub!
Real PowerShell Output from the Google News Agent Project
Here’s exactly what happened when I pushed the Google News Agent to GitHub. You’ll see actual PowerShell terminal output for each command.
Image 1: Cloning the Repository & Navigating
Command executed:
git clone https://github.com/kajalishere/google-news-agent.git
cd google-news-agent
dir
The git clone command downloads your repository from GitHub to your local machine. You see the enumeration, counting, compressing, and unpacking of objects. Once cloned, cd moves into the directory and dir displays all the project files.
Image 2: Navigating the Project & File Operations
Here you can see actual file navigation commands. Sometimes you might try to copy files from old projects ,the screenshot shows a common error when the source path doesn’t exist. Pay attention to the file structure.
Image 3: Git Config, Add, Commit, and Push to GitHub
Commands executed:
git config — global user.name “Yourname”
git config — global user.email “youremaild@gmail.com”
git add .
git commit -m “feat: Add Google News Agent — Python CLI for fetching news from Google News RSS feeds”
git push origin main
SUCCESS! The output shows:
· Enumerating objects: 7, done.
· Counting objects: 100% (7/7), done.
· Compressing objects: 100% (5/5), done.
· Writing objects: 100% (5/5), 5.69 KiB | 2.84 MiB/s, done.
· To https://github.com/kajalishere/google-news-agent.git
· 332b736..d525b02 main -> main
Get Kajal’s stories in your inbox
Join Medium for free to get updates from this writer.
This confirms your code has been successfully uploaded to GitHub!
Image 4: Push Rejection Error — When Remote Has Changes
Command executed:
git push origin main
ERROR OUTPUT:
! [rejected] main -> main (fetch first)
error: failed to push some refs to ‘https://github.com/kajalishere/google-news-agent.git'
hint: Updates were rejected because the remote contains work that you do not have locally.
hint: This is usually caused by another repository pushing to the same ref.
hint: You may want to first integrate the remote changes (e.g., ‘git pull’)
hint: before pushing again.
What happened:
GitHub has changes you don’t have locally. This usually happens when you edit files directly on GitHub’s website or when someone else pushed changes.
The fix is coming in the next step!
Image 5: Git Pull, Merge, and Successful Push
Commands executed:
git pull origin main
git push origin main
OUTPUT FROM GIT PULL:
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
Unpacking objects: 100% (3/3), done.
From https://github.com/kajalishere/google-news-agent
* branch main -> FETCH_HEAD
d525b02..968822d main -> origin/main
Merge made by the ‘ort’ strategy.
README.md | 401 +++++++++++++++++++++++++++++++++++++++
1 file changed, 162 insertions(+), 239 deletions(-)
The git pull downloads GitHub’s latest changes and merges them with your code.
OUTPUT FROM GIT PUSH (AFTER PULL):
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 16 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 590.51 KiB | 19.68 MiB/s, done.
Total 9 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 1 local object.
To https://github.com/kajalishere/google-news-agent.git
968822d..5444455 main -> main
SUCCESS! Your code is now on GitHub after pulling the remote changes.
When Things Go Wrong: Common Errors & Solutions
Error 1: Git Push Rejection
! [rejected] main -> main (fetch first)
error: failed to push some refs to ‘https://github.com/...'
hint: Updates were rejected because the remote contains work
hint: that you do not have locally.
What happened:
GitHub has changes you don’t have locally. This usually happens when you edit files directly on GitHub’s website or when someone else pushed changes.
Solution:
# Step 1: Pull the remote changes first
git pull origin main
# Step 2: Now push your changes
git push origin main
The git pull downloads GitHub’s changes and merges them with your code. After that, git push will succeed.
Error 2: Git Repository Not Found
fatal: not a git repository (or any of the parent directories): .git
What happened:
You’re not in a Git repository directory. Git can’t find the .git folder.
Solution:
# Check your current directory
pwd
# Navigate to your repository root directory
cd C:\Users\kajal\google-news-agent
# Verify you’re in the right place
dir # You should see a .git folder
Make sure you’re in the root of your repository where the .git folder exists.
Error 3: Please Tell Me Who You Are
*** Please tell me who you are.
Run
git config — global user.email “you@example.com”
git config — global user.name “Your Name”
What happened:
Git doesn’t know your name and email. This happens on first-time Git setup.
Solution:
git config — global user.name “Your Name”
git config — global user.email “your-email@gmail.com”
Run these commands to configure Git globally. After that, commits will work.
Complete Command Sequence
Here’s everything in order. Copy and paste these commands into PowerShell:
# Configure Git (one-time setup)
git config — global user.name “Your Name”
git config — global user.email “your-email@gmail.com”
# Navigate to your repository
cd C:\Users\username\your-repo-name
# Check status
git status
# Stage all changes
git add .
# Commit with message
git commit -m “feat: Add your project description”
# Pull latest changes from GitHub
git pull origin main
# Push to GitHub
git push origin main
5 Best Practices for Pushing Code
1. Commit frequently :Make small, logical commits. Don’t wait to commit a hundred files at once.
2. Write descriptive messages :Use conventional prefixes:
· feat: (new feature)
· fix: (bug fix)
· docs: (documentation)
· style: (formatting)
3. Always pull before pushing :Run git pull before git push to avoid rejection errors.
4. Review with git status :Always check git status to see what you’re about to commit.
5. Use .gitignore :Create a .gitignore file to exclude files like passwords, node_modules, __pycache__, .env, etc.
Conclusion
Master this workflow, and you’ve mastered the most essential skill in modern software development. Your code is now tracked, backed up, and ready for collaboration!
The key takeaway: Always pull before you push. This simple rule will save you from 90% of Git headaches.
You can find the complete Google News Agent project at https://github.com/kajalishere/google-news-agent
Happy coding!







