DEV Community

arielle martin
arielle martin

Posted on

Intro to Git for Beginners: Branching, Merging, and Commit Best Practices

If you're new to coding, you've probably heard people talk about Git, but what exactly is it, and how do you use it?

This guide breaks down branching, merging, and committing in simple, easy-to-follow steps. These are the core skills that help you keep your code organized and collaborate with others.

🧠 What is Git?

Git is a tool that helps you track changes in your code. Think of it like a "save" button for your code, but way more powerful.

With Git, you can:

  • Go back to an earlier version of your work

  • Try out new ideas without messing up your main project

  • Work with other developers without stepping on each other’s toes

🌿 What’s a Branch?

A branch is like a copy of your project where you can safely make changes.

Let’s say you're building a website. If you want to try a new feature—like a dark mode—you don’t want to break the main version of your site. So you create a branch to test it out.

Here’s how to do it:

git checkout -b dark-mode

This creates a new branch called dark-mode and switches you to it.

When you’re done working, you can go back to the main version like this:

git checkout main

🔀 How to Merge Your Work
Once your new feature is working and tested, you’ll want to merge it into your main code.

Here’s what to do:
to save your changes

git add .
git commit -m "Add dark mode feature"

to switch back to main branch

git checkout main

to merge your changes into main

git merge dark-mode

This brings all your changes from the dark-mode branch into the main project.

Before merging, make sure your main branch is up to date:

git pull origin main

✅ Commit Messages: Say What You Did
Every time you save your changes in Git, you make a commit. This is like writing a note that says, “Here’s what I just changed.”

Good commit messages help you and others understand what happened.

Tips:

Keep it short and clear

Start with an action word (like “Add,” “Fix,” “Update”)

Examples:
git commit -m "Fix broken link on homepage"
git commit -m "Add contact form"

You're on Your Way 🚀
Learning Git takes practice, but once you get the hang of it, you’ll wonder how you ever coded without it.

Want more tips? Visit my portfolio for tutorials, projects, and resources to help you grow.

Top comments (0)