Getting Started with Git and GitHub – A Beginner's Guide
Whether you're a developer, DevOps engineer, or student, understanding Git and GitHub is essential to working with code collaboratively and safely. In this post, I’ll walk you through the basics using simple explanations and handmade-style diagrams.
What Is Git and Why Is It Important?
Git is a version control system. Think of it as a time machine for your code. Every time you make changes, Git lets you:
- Save snapshots (called commits)
- Go back to earlier versions
- Collaborate with others without overwriting their work
Why it matters:
- Track changes
- Collaborate on projects
- Reduce the risk of losing work
🌱 Main Branch vs Master Branch
Both refer to the default branch in a Git repository. Historically, it was called master
, but today most tools use main
to encourage more inclusive language
🆚 Git vs GitHub
Feature | Git | GitHub |
---|---|---|
Type | Tool (installed locally) | Platform (online) |
Purpose | Version control system | Host for Git repositories |
Usage | Works offline | Needs internet connection |
Command line | Yes | No (but has CLI support) |
📦 How to Create a GitHub Repository
- Go to https://github.com
- Click New to create a new repo
- Name it (e.g.,
DevOps
) - Choose public/private, add README if needed
- Click Create Repository
🔁 Local vs Remote Repositories
- Local repository: On your computer
- Remote repository: Hosted on GitHub
To sync both:
git remote add origin https://github.com/your-username/DevOps.git
git push -u origin main
Tasks Walkthrough
✅ Task 1: Set Username and Email
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
These details will appear in your commits.
✅ Task 2: Create and Connect to GitHub
- On GitHub, create a repo called
DevOps
. - On your terminal:
mkdir DevOps
cd DevOps
git init
git remote add origin https://github.com/your-username/DevOps.git
✅ Task 3: Add and Push a File
mkdir -p Git
echo "My Git journey begins!" > Git/Day-02.txt
git add .
git commit -m "Add Day-02 Git task"
git push -u origin main
we have now created a file locally and pushed it to GitHub.
Final Thoughts
Learning Git can seem overwhelming, but with practice and visuals, it becomes second nature. Version control is a must-have skill in the tech
Stay tuned for more DevOps tools in this journey!
Top comments (0)