Git for Beginners: Push Your First Code to GitHub

Rohit KumarRohit Kumar
2 min read

Struggling to understand Git? Let’s simplify it step-by-step — from setup to pushing your first code.


🚀 What Is Git?

Git is a version control system. Think of it as a time machine for your code — it tracks every change, helps you collaborate, and lets you roll back if something breaks.


🔧 Prerequisites


✅ Step-by-Step Guide

1️⃣ Set Up Git (Only Once)

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

2️⃣ Initialize Your Local Git Repo

cd your-project-folder
git init

This starts Git version tracking in your folder.


3️⃣ Stage and Commit Your Code

git add .
git commit -m "Initial commit"

This saves a snapshot of your files.


4️⃣ Create a GitHub Repository

  1. Go to GitHub

  2. Click New Repository

  3. Name it (e.g., my-first-repo)

  4. Keep it empty (no README or .gitignore)

  5. Click Create Repository


Copy the repo URL GitHub gives you and run:

git remote add origin https://github.com/yourusername/my-first-repo.git

6️⃣ Push Your Code to GitHub

For older Git versions:

git push -u origin master

For newer Git:

git push -u origin main

🎉 That’s it! Your code is now live on GitHub.


🛠️ Common Git Errors and Fixes

🔸 Error: remote origin already exists

git remote remove origin
git remote add origin <url>

🔸 Error: Updates were rejected...

git pull origin main --allow-unrelated-histories
git push -u origin main

🧠 Summary

Git CommandWhat It Does
git initStart Git in your folder
git add .Stage all files
git commit -mSave a snapshot
git remote add originLink to GitHub
git pushUpload code to GitHub

💬 Have questions or got stuck while following this guide?

Drop your doubts in the comments — I’d love to help you out!

— ✍️ Written by Rohit @ TechWithRohit

0
Subscribe to my newsletter

Read articles from Rohit Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rohit Kumar
Rohit Kumar

👨‍💻 Working IT professional | ✍️ Beginner-friendly tech writer I simplify tools like Git, SQL, and developer workflows so that even total beginners can get started with confidence. 🚀 On a mission to break down complex tech into easy steps — one blog at a time. 📚 Topics I write about: Git, GitHub, SQL, Dev tools, Productivity for new developers 💡 Let’s grow together — follow for simple, clear, no-fluff tutorials.