1/15/2026Git

Git for Beginners: A Step-by-Step Guide

Master the absolute basics of Git: cloning, branching, and pushing code safely. Essential for every developer.

Git for Beginners: A Step-by-Step Guide

Git for Beginners: A Step-by-Step Guide

Introduction

Git is the industry standard for version control. Whether you're a solo developer or part of a huge team, mastering Git is essential. This guide covers the absolute basics to get you started.

What is Git?

Git is a distributed version control system that tracks changes in your source code during software development. It allows you to:

  • Revert files to previous states.
  • Track who made changes and why.
  • Work on parallel branches without affecting the main code.

How to Clone from GitHub?

Cloning creates a local copy of a repository from a remote source like GitHub.

  1. Go to the repository page on GitHub.
  2. Click the green Code button and copy the URL (HTTPS or SSH).
  3. Open your terminal and run:
    git clone <repository-url>
    
    Example:
    git clone https://github.com/username/project-name.git
    

How to Create a Branch?

Branches let you work on new features or fixes in isolation. To create and switch to a new branch:

git checkout -b feature/my-new-feature

Tip: Use descriptive names like bugfix/login-error or feature/user-profile.

How to Push to a Branch

Once you've made commits, you need to send them to the remote repository.

git push -u origin feature/my-new-feature

The -u flag sets the "upstream" link, so you can just run git push next time.

How to Pull from a Branch

Pulling from your own branch: To update your local branch with changes from the remote:

git pull origin feature/your-branch-name

Pulling from another branch (e.g., master/main): To get the latest updates from the main codebase into your branch:

git checkout feature/your-branch-name
git pull origin main

The Golden Rule: Never Push to Master

Directly pushing to master (or main) is risky. It can bypass code reviews and break the production application. Always:

  1. Create a branch.
  2. Make changes.
  3. Push the branch.
  4. Create a Pull Request (PR).

How to Raise a PR

A Pull Request notifies teammates that you have changes ready to be merged.

  1. Push your branch to GitHub.
  2. Go to the repository on GitHub.
  3. You'll often see a "Compare & pull request" button. Click it.
  4. Add a title and description.
  5. Click Create Pull Request.