Git: From Installation to Your First Commit

Git is an awesome tool that developers everywhere use to keep track of their code. In this article, we’ll walk you through everything - from setting it up to making your first commit-breaking it down step-by-step with handy tips for beginners.

1. What’s Git and Why Use It?

The Basics

Git is a distributed version control system cooked up by Linus Torvalds back in 2005. It lets you track changes in your code, save its history, and jump back to earlier versions if you need to. It’s fast, flexible, and super reliable, which is why it’s the go-to tool for developers.

Teamwork Makes the Dream Work

Git shines when you’re working with others. It lets multiple people hack away at a project at the same time, sync up their changes, and avoid stepping on each other’s toes. With branches, everyone can work on their own piece of the puzzle and then merge it into the main codebase later.

Why Use Git Solo?

Even if you’re flying solo, Git’s got your back:

Start using Git with your very first project—it’ll build a solid habit and make life easier down the road.

2. Getting Git Installed

Options for Different Systems

Git works on pretty much anything: Linux, macOS, Windows—you name it. You can grab it from the official site (git-scm.com) or use your system’s package manager.

Installing on Linux and macOS

Check it worked with:
git --version

Installing on Windows with a GUI

Head to git-scm.com and download the installer. Run it and follow the steps:

3. Setting It Up

Adding Your Name and Email

Before you commit anything, tell Git who you are:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

The --global flag sets this for all your projects. Peek at your settings with:
git config --list

What Happens If You Skip This?

If you try to commit without setting these up, Git will throw a fit:
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.


It won’t let you commit until you sort this out.

4. Logging Into Your Account

Ways to Log In on Different Platforms

Git itself doesn’t need a login, but to work with remote repos (like GitHub, GitLab, or Bitbucket), you’ll need to sign in:

Via HTTPS: Use your username and a token (Personal Access Token):
git remote add origin https://github.com/username/repository.git

It’ll ask for your token the first time you push.

Via SSH: Set up an SSH key:

Logging In Through Your IDE

5. Starting Git in Your Project

Setting Up Git Locally

Grabbing Code for Team Projects

GitHub/GitLab: Copy the repo URL (HTTPS or SSH) and run:
git clone https://github.com/username/repository.git

This pulls the code down and connects it to the remote repo.

6. How to Work with Git Day-to-Day

Switching Branches

Make a new branch for your changes:
git checkout -b feature/branch-name.

Switch to your new branch branch:
git checkout branch-name.

Grabbing the Latest Code

Keep your local copy fresh:
git pull origin main

Making a Commit

Pushing Your Commit

Send your changes to the remote repo:
git push origin feature/branch-name

What If You Didn’t Pull Before Committing and Pushing?

If someone else updated the remote branch and you didn’t pull those changes before committing, git push will fail. Here’s how to undo your last commit without losing your work, sync up, and push your changes without a hitch:
git reset --soft HEAD^

HEAD^ points to your last commit. --soft undoes the commit but keeps your changes staged and ready to go.

If your files are staged but you want them back in your working area:
git restore --staged .

After undoing the commit, here’s how to get the latest code and push your work:

7. Speeding Up Git Commands

You can chain commands with && to save time. These combos are perfect for repetitive tasks and work great with Commands Manager - a tool that lets you store, search, and run commands with shortcuts, plus sync them across devices.

Examples:

Using Commands Manager

With Commands Manager:

Cloud sync keeps your commands handy wherever you work.

8. Wrapping Up

Git’s more than just a tool - it’s a way to keep your code in check. We’ve covered installing it, setting it up, starting a project, and making your first commit. With the basics down and tricks like Commands Manager in your pocket, you’ll be coding smarter solo or with a team. Keep practicing, and Git will feel like second nature!