Git and GitHub for Beginners

  • Admin
  • 1 min read

Git vs. GitHub

Git is version control software that runs on your computer, tracking changes to your files over time. GitHub is a website that hosts Git repositories online so you can back them up and collaborate with others. They’re related but not the same thing.

Setting Up a Repository

git init git add . git commit -m "Initial commit"

The Core Workflow

git status # see what changed git add file.txt # stage a specific file git commit -m "Fix header bug" git push origin main # send commits to GitHub

Cloning an Existing Project

git clone https://github.com/username/repo.git cd repo

Branching

Branches let you work on a feature without affecting the main codebase until you’re ready to merge:

git branch feature-login git checkout feature-login # or in one step: git checkout -b feature-login

Merging Changes

git checkout main git merge feature-login

Undoing Mistakes

git checkout -- file.txt # discard unstaged changes git reset HEAD file.txt # unstage a file git revert <commit-hash> # safely undo a pushed commit

Practice Exercise

Create a new repository, make three commits with meaningful messages, create a branch, make a change there, and merge it back into main.

Admin

About the author

Admin

Instructor and technical writer at tutorials.in

Writes beginner lessons for tutorials.in. Each lesson is checked against the language or tool documentation, and examples are run before publishing.

Reviewed by the editorial team before publishing. Last updated August 9, 2026.

Ask a question

Be specific about what you tried. Questions with a code sample and the exact error message are answered fastest.