Think of Git as a magic “undo” button and a time machine for your code. It tracks every change you make, allowing you to experiment without the fear of breaking everything. GitHub, on the other hand, is the cloud platform where you store those Git repositories, collaborate with others, and showcase your work to the world.
If you are brand new to GitHub, you can check out the previous guide first.
Here is everything you need to know to get set up and start pushing code like a pro.
Part 1: Setting Up Your Developer Identity
Before touching the command line, you need a place to store your code. Head over to GitHub and create an account.
Your GitHub profile is much more than just cloud storage; in the modern tech industry, it is essentially your living, breathing resume. When you apply for a job, recruiters and senior developers will look at your GitHub to see what kind of code you write, how often you contribute, and what projects you are passionate about.
Part 2: The Essential Git Commands
Once your profile is set up, it is time to connect your computer to GitHub using Git. You don’t need to memorize hundreds of commands to be productive. These are the essential commands you will use every single day as a developer.
1. Getting Started: Clone or Init
Before you can track code, you need a repository (a “repo”). You can either bring an existing project down from GitHub, or start a brand new one on your computer.
- To download an existing project from GitHub:
git clone https://github.com/username/repository-name.git
This creates a local copy of the project on your machine so you can start working on it.
- To start tracking a brand new, local project:
git init
Navigate to your project folder in your terminal and run this. It creates a hidden .git folder that starts tracking your files.
2. Checking Your Status
When you are working, you will frequently want to see which files you have changed, added, or deleted.
- To see the current state of your project:
git status
This is your compass. It tells you exactly what Git sees right now. Red files are modified but not ready to save; green files are ready to be saved.
3. Staging Changes: The Waiting Room
Git doesn’t automatically save your changes. You have to explicitly tell it which files you want to bundle together for your next save point. This is called “staging”.
- To stage a specific file:
git add index.html
- To stage ALL changed files at once (the most common method):
git add .
4. Committing: Taking the Snapshot
Once your files are staged, you need to take a permanent snapshot of them. This is called a “commit”. Always leave a clear, descriptive message so your future self (and your teammates) knows what you changed.
- To save your staged changes:
git commit -m "Added initial HTML file"
5. Pushing: Sending it to the Cloud
You have saved your changes locally, but if your computer crashes right now, that code is still lost. You need to “push” it up to your remote repository on GitHub.
- To upload your local commits to GitHub:
git push origin main
6. Pulling: Syncing with Your Team
If you are working with other developers, or working from a different computer, the code on GitHub might be newer than the code on your local machine.
- To download the latest changes from GitHub:
git pull
The Daily Developer Workflow
When you sit down to code, your process will almost always look exactly like this:
- git pull (Make sure you have the latest updates)
- Write your awesome code
- git status (Check what you changed)
- git add . (Stage the changes)
- git commit -m “Describe what you did” (Save the changes)
- git push (Send it to GitHub)
Master this cycle, and you will be collaborating like a senior software engineer in no time. Happy coding!