Beginner 2 min read

Git and GitHub for Beginners

Git is a tool that tracks changes in your code. GitHub is where you store and share that code online.

Think of Git as your project's save history — and GitHub as the cloud backup.


Install Git

Download from git-scm.com and install.

Verify:

git --version

Configure Git (Do This Once)

Tell Git who you are before using it:

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

This name and email appears on every commit you make.


Core Workflow

Every time you work on a project, you follow these steps:

1. Initialize a repository

cd your-project
git init

2. Check what changed

git status

3. Stage your files

git add .          # Stage everything
git add file.txt   # Stage one file

4. Commit (save a snapshot)

git commit -m "describe what you did"

Good commit messages: "add login page", "fix navbar bug", "update README"

5. Push to GitHub

git remote add origin https://github.com/username/repo.git
git branch -M main
git push -u origin main

Next time you push, just:

git push

Other Commands You'll Use Daily

git pull          # Get latest changes from GitHub
git log           # View commit history
git clone <url>   # Download a GitHub repo
git diff          # See what changed since last commit

How Git Tracks Your Code

Working files → git add → Staged → git commit → Local repo → git push → GitHub

Every commit is a snapshot. You can always go back to any previous commit.


Common Errors

fatal: not a git repository → You forgot git init. Run it in your project folder.

rejected — non-fast-forward → Someone else pushed changes. Run git pull first, then push.

Permission denied (publickey) → GitHub no longer accepts passwords. Set up SSH or use a Personal Access Token.


Next Step

👉 Set up SSH so you never type your password again