If you are new to coding, chances are you've already heard developers mention Git and GitHub. At first, they may sound complex-even intimidating. The good news is that they are far less scary than they seem, and once you understand them, then you will wonder why you even coded without them.
Git and GitHub are essential tools that help you track changes in your code, collaborate with others, and protect your work from costly mistakes. Whether you are building a small personal project or contributing to a team, these tools quickly become indespensable.
In this guide, we’ll walk through everything step by step:
What Git is and why version control matters?
How to track changes in your code locally using Git
How to push your project to GitHub so it’s backed up and shareable
How to pull updates from GitHub to get the latest version of your
code
By the end, you’ll understand how Git fits into everyday development and feel confident using it in your own projects.
What Is Git—and Why Do You Need Version Control?
Git is a version control system. The simplest way to think about it is as a powerful undo button combined with a time machine for your code.
Every time you save a meaningful change, Git records:
What changed
When it changed
Why it changed
This means you can:
Go back to any previous version of your project.
See exactly what was added, removed, or modified.
Work on multiple features without breaking your main code.
Collaborate safely with other developers.
Why Version Control Matters
Imagine you’re working on a project and accidentally delete an important file. Without version control, that mistake could cost you hours—or days—of work.
With Git:
You always have a complete history of your project.
You can experiment freely, knowing you can revert at any time.
Multiple people can work on the same project without overwriting each other’s work.
This is why Git is an industry standard and a required skill in most development roles.
Getting Set Up
Before we begin, make sure you have the following:
Git installed on your computer
Download it from [https://git-scm.com/downloads] and follow the installation instructions.A GitHub account
Sign up at [https://github.com] if you don’t already have one.Configure Git with your name and email.
git config --global user.name "Your Name"
git config --global user. email "your.email@example.com"
You’re now ready to start using Git.
Tracking Changes Locally with Git
Let’s begin with a simple project on your computer.
- Create a new project folder
mkdir my-awesome-project
cd my-awesome-project
- Initialize Git in the folder
git init
This creates a hidden. git folder where Git stores your project’s history.
- Create a file
echo "Hello, world!" > index.html
- Check the project status
git status
Git will tell you that index.html is untracked—it sees the file but isn’t tracking changes yet.
- Add files to the staging area
git add index.html.
# or add everything
git add.
The staging area is where you prepare changes before saving them.
- Commit your changes
git commit -m "Initial commit: add hello world page”
A commit is a snapshot of your project at a specific point in time.
- View your project history
git log
You’ll see a list of commits with dates, messages, and unique IDs.
- Make more changes
Edit index.html, then run:
git status
git diff
git add.
git commit -m "Update greeting to be friendlier”
This cycle—add → commit → repeat—is the core Git workflow.
Pushing Code to GitHub (Sharing Your Project Online)
Now let’s back up your project and make it accessible on GitHub.
- Create a new repository on GitHub
Go to https://github.com/new
Name the repository.
Do not initialize it with a README.
Click Create repository.
Copy the repository URL. It will look like:
https://github.com/your-username/my-awesome-project.git
- Link your local project to GitHub
git remote add origin https://github.com/your-username/my-awesome-project.git.
- Push your code to GitHub
git push -u origin main
The first push may ask you to authenticate. Once it completes, refresh the GitHub page—you’ll see your files online.
Future updates are simpler:
git add.
git commit -m "Your message”.
git push
Pulling Code from GitHub
There are two common situations where pulling comes in handy.
Starting a project from GitHub (cloning)
git clone https://github.com/their-username/their-project.git
cd their-project
This downloads a full copy of the project and its history.Updating your local project (pulling)
git pull
This fetches the latest changes from GitHub and merges them into your local files. If needed, you can specify the branch:
git pull origin main
Practice on a small personal project and you'll get comfortable fast. Git might feel overwhelming at first, but it's one of those tools that makes you a much better developer once you know it.
Happy coding!
Top comments (0)