Every professional developer uses Git and GitHub. If you're not using version control, you're working without a safety net — one wrong delete and your work is gone. Git tracks every change you make to your code, lets you experiment safely, and makes collaboration with other developers possible. This guide explains everything from scratch.

Git vs GitHub: What's the Difference?

Git is a version control system — software that runs on your computer and tracks changes to your files. It's free and open source.

GitHub is a website that hosts Git repositories online. It's like Google Drive for code, but with powerful collaboration features. GitHub is where developers share code, contribute to open source, and showcase their work to employers.

Think of it this way: Git is the tool, GitHub is the platform. You can use Git without GitHub (storing repos locally), but you can't use GitHub without Git.

Installing Git

Download Git from git-scm.com. During installation, choose "Git Bash" on Windows. On Mac, Git comes pre-installed or install it via Homebrew: brew install git. On Linux: sudo apt install git.

After installing, configure your identity:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Core Git Concepts

Repository (Repo)

A repository is a folder that Git is tracking. It contains your project files plus a hidden .git folder where Git stores all the history.

Commit

A commit is a snapshot of your project at a specific point in time. Think of it like a save point in a video game. Each commit has a unique ID and a message describing what changed.

Branch

A branch is a parallel version of your code. The default branch is called main. You create branches to work on new features without affecting the main code. When the feature is ready, you merge it back.

Remote

A remote is a version of your repository stored on a server (like GitHub). You push your local commits to the remote to back them up and share with others.

Your First Git Workflow

# 1. Create a new project folder and initialize Git
mkdir my-project
cd my-project
git init

# 2. Create a file
echo "# My Project" > README.md

# 3. Check what Git sees
git status

# 4. Stage the file (tell Git to include it in the next commit)
git add README.md
# Or stage everything: git add .

# 5. Commit with a message
git commit -m "Initial commit: add README"

# 6. Check the commit history
git log --oneline

Connecting to GitHub

# 1. Create a new repository on github.com (click the + button)
# 2. Copy the repository URL

# 3. Connect your local repo to GitHub
git remote add origin https://github.com/yourusername/my-project.git

# 4. Push your commits to GitHub
git push -u origin main

# After the first push, you can just use:
git push

The Daily Git Workflow

Once your project is set up, your daily workflow looks like this:

# 1. Pull latest changes (if working with others)
git pull

# 2. Make changes to your files...

# 3. Check what changed
git status
git diff

# 4. Stage your changes
git add .

# 5. Commit
git commit -m "Add user authentication feature"

# 6. Push to GitHub
git push

Working with Branches

# Create and switch to a new branch
git checkout -b feature/login-page
# Modern syntax: git switch -c feature/login-page

# Make changes, commit them...
git add .
git commit -m "Add login form HTML and CSS"

# Switch back to main
git checkout main

# Merge your feature branch into main
git merge feature/login-page

# Delete the branch (optional, after merging)
git branch -d feature/login-page

Pull Requests (PRs)

A pull request is a GitHub feature that lets you propose changes to a repository. Instead of merging directly, you create a PR and others can review your code, leave comments, and approve or request changes before merging.

The PR workflow:

  1. Create a branch and make your changes
  2. Push the branch to GitHub: git push origin feature/my-feature
  3. Go to GitHub and click "Compare & pull request"
  4. Write a description of what you changed and why
  5. Request reviewers if working in a team
  6. After approval, merge the PR

Cloning an Existing Repository

# Download a repository from GitHub to your computer
git clone https://github.com/username/repository-name.git

# This creates a folder with all the code and history
cd repository-name

Handling Merge Conflicts

A merge conflict happens when two people change the same line of code. Git marks the conflict in the file:

<<<<<<< HEAD
Your version of the code
=======
Their version of the code
>>>>>>> feature/their-branch

To resolve: edit the file to keep the correct version, remove the conflict markers, then git add and git commit.

Essential Git Commands Cheat Sheet

git init              # Initialize a new repo
git clone <url>       # Clone a remote repo
git status            # See what's changed
git add .             # Stage all changes
git commit -m "msg"   # Commit with message
git push              # Push to remote
git pull              # Pull from remote
git branch            # List branches
git checkout -b name  # Create and switch branch
git merge name        # Merge branch into current
git log --oneline     # View commit history
git diff              # See unstaged changes
git stash             # Temporarily save changes
git stash pop         # Restore stashed changes

GitHub Profile Tips

Your GitHub profile is your developer portfolio. Employers look at it. Make it count: