DEV Community

JOAN NJOKI
JOAN NJOKI

Posted on

🚀 Getting Started with Git and GitHub: A Beginner’s Guide

🛑 The "What" and "Why": Git vs. GitHub 🧐
Git is a distributed version control system that tracks code changes, and allows you to:

  • go back to earlier versions if something breaks
  • work with teammates without overwriting each other's work
  • see who made what changes and when.

GitHub is a cloud-based platform that hosts Git repositories, providing additional tools for collaboration, issue tracking, and code review. GitHub offers remote repository hosting and integrates with Git for easier teamwork.
It's like the "showcase" for your code, enabling collaboration, public visibility for your portfolio, and secure backups of your work.
If Git is the "camera" taking snapshots of your work, GitHub is the "online gallery" where those snapshots are stored and shared.

🛠 Your First Steps: Setting Up a Project 📂
1. Tracking changes
To start tracking a project, you first need to initialize Git in your project folder using your terminal: git init
Once Git is watching your folder, tracking changes follows a simple three-step "Save" process:

  1. check your status (git status): see files that are untracked (new) or modified
  2. stage (git add): Pick which changes you want to include in your next "snapshot."
  3. commit (git commit): take the snapshot and give it a descriptive label.

2. Pushing code to GitHub
"Pushing" is the act of sending your local commits (the snapshots on your computer) to a remote server like GitHub. This makes your code accessible to others and acts as a backup.
The steps are:

  1. Create a new repository on GitHub.com.
  2. Copy the URL of the repository (e.g., https://github.com/your-username/my-project.git).
  3. Link your local folder to GitHub (you only do this once): git remote add origin https://github.com/your-username/my-project.git
  4. Push code git push -u origin main

3. Pulling code from GitHub
Pulling is essentially a combination of fetching the latest version from GitHub and merging it into your local files using the command git pull origin main

Basic Workflow Summary:

  1. Create a new repository on GitHub using the web interface
  2. Clone it to your machine with git clone [url] (this creates your local repository)
  3. Make some changes to the files in your working directory
  4. Stage changes with git add . (moving them to the staging area)
  5. Commit with git commit -m "Describe your changes"
  6. Push to GitHub with git push -u origin main

Happy Coding and may your code always be perfectly version-controlled! ✨💻

Top comments (0)