How to Use GitHub: A Beginner's Guide to Version Control and Collaboration

2026-06-05·Getting Started

Key Takeaways

  • GitHub is built on Git, which tracks every change in your code—like a time machine for your files.
  • You can collaborate with others by creating branches, making pull requests, and reviewing code.
  • GitHub Actions automates repetitive tasks like testing or deployment.
  • A well-maintained GitHub profile serves as a public portfolio for employers.

What Is GitHub and Why Bother?

GitHub is a cloud platform that hosts Git repositories. Git itself is a version control system—it records snapshots of your project so you can roll back to any point. GitHub adds a social layer: you can share code, review others' work, and contribute to open-source projects.

I’ve seen beginners skip version control and later lose days of work when they broke something. GitHub saves you from that pain. Plus, over 100 million developers use it (as of 2023). If you're learning to code, your GitHub profile is your resume.

Step 1: Install Git and Create a GitHub Account

First, install Git on your computer. Download it from [git-scm.com](https://git-scm.com/). On Windows, use the default options except choose "Git from the command line and also from 3rd-party software." On Mac, you can use Homebrew: `brew install git`.

Then sign up at [github.com](https://github.com/). Choose a username that looks professional—avoid joke names if you want a job later.

Step 2: Set Up Your First Repository

A repository (repo) is a folder for your project. Let's create one:

1. Click the green "New" button on GitHub.

2. Name it `my-first-repo`.

3. Add a README (a markdown file that describes your project).

4. Choose public or private (public is fine for learning).

Now connect your local folder to this repo. Open your terminal and run:

```bash

git init

git add .

git commit -m "first commit"

git remote add origin https://github.com/your-username/my-first-repo.git

git push -u origin main

```

The `git add .` stages all files, `git commit` saves them locally, and `git push` uploads them to GitHub. You should see your files appear on the website.

Step 3: Track Changes with Commits

Every commit is a save point. I recommend committing every time you complete a small task—like adding a function or fixing a bug. This way, you can always go back.

Example workflow:

```bash

echo "# My Project" > README.md

git add README.md

git commit -m "Add README"

git push

```

Use `git log` to see your history. Each commit has a unique hash (like a1b2c3d). To revert to a previous commit: `git checkout a1b2c3d .` (but be careful—this overwrites current files).

Step 4: Collaborate with Branches and Pull Requests

Branches let you work on features without messing up the main code. Create a branch:

```bash

git branch my-feature

git checkout my-feature

# or shorter: git checkout -b my-feature

```

Make changes, commit, then push the branch: `git push origin my-feature`.

On GitHub, you'll see a button "Compare & pull request." Click it, write a description, and ask someone to review. This is how teams work. The reviewer can leave comments, request changes, or approve. Once merged, the feature joins the main branch.

Branch vs. Fork: A Quick Comparison

FeatureBranchFork

-----------------------
Where it livesSame repoYour own copy of someone else's repo
Best forTeam projectsContributing to open source
How to sync`git merge`Pull request from original repo

Forks are common in open source. You fork a project, make changes, then submit a pull request to the original.

Step 5: Automate with GitHub Actions

Actions let you run code automatically when you push. For example, you can run tests or deploy to a server.

Create a file at `.github/workflows/ci.yml` in your repo:

```yaml

name: CI

on: [push, pull_request]

jobs:

test:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v4

- run: echo "Running tests..."

```

Push this file, and GitHub will run the workflow. Check the "Actions" tab to see results. I use Actions to test my Python code—it catches bugs before they reach production.

Step 6: Build a Portfolio on GitHub

Your GitHub profile page (github.com/your-username) shows your repositories, contributions, and activity. To make it stand out:

  • Add a README to your profile by creating a repo named exactly `your-username/your-username`.

  • Pin your best projects (up to 6).
  • Each project should have a clear README, a license, and maybe a live demo link.

I’ve seen developers get job interviews simply because their GitHub showed real projects with clean code.

Common Pitfalls and Tips

  • Don't commit sensitive data. Use a `.gitignore` file to exclude passwords or API keys. GitHub will warn you if you push them.
  • Write good commit messages. Bad: "fix stuff." Good: "Fix CSS layout bug on mobile nav."
  • Pull before you push. Always run `git pull` first to avoid merge conflicts.

FAQ

Q: What's the difference between Git and GitHub?

Git is the command-line tool that tracks changes locally. GitHub is a website that stores your Git repositories online and adds collaboration features like pull requests and issues. You can use Git without GitHub, but not the other way around.

Q: How do I undo a commit I already pushed?

Use `git revert ` to create a new commit that undoes the changes. This is safer than `git reset` because it preserves history. If you haven't pushed, you can use `git reset --soft HEAD~1` to uncommit but keep your changes.

Q: Do I need to know command line to use GitHub?

Not necessarily. GitHub Desktop is a GUI app that handles basic tasks. But I recommend learning the command line—it’s faster, more powerful, and essential for advanced features like rebasing or interactive staging.