Git for Beginners: Push Your First Code to GitHub


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
Git installed on your computer → Download Git
A GitHub account → Create one here
A folder/project on your machine
✅ 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
Go to GitHub
Click New Repository
Name it (e.g.,
my-first-repo
)Keep it empty (no README or .gitignore)
Click Create Repository
5️⃣ Link Your Local Repo to GitHub
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 Command | What It Does |
git init | Start Git in your folder |
git add . | Stage all files |
git commit -m | Save a snapshot |
git remote add origin | Link to GitHub |
git push | Upload 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
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.