Git & GitHub

Beginner 20 min read Lesson 1 of 6

Git tracks changes to your code over time. GitHub hosts Git repositories online so you can back up code and collaborate with others.

Initializing a repository

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

Connecting to GitHub

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

The daily workflow

git status                 # see what changed
git add .                  # stage all changes
git commit -m "Add login page"
git push                   # send to GitHub

Branching

git checkout -b feature/student-search
# ...make changes...
git add .
git commit -m "Add student search box"
git push -u origin feature/student-search

Then open a Pull Request on GitHub to merge it into main once it's reviewed.

A .gitignore for .NET projects

bin/
obj/
*.user
.vs/
appsettings.Development.json

Never commit build output or secrets — this file tells Git to skip them entirely.

Undoing mistakes

git checkout -- filename.cs     # discard uncommitted changes to one file
git reset --soft HEAD~1         # undo the last commit, keep the changes staged
git revert <commit-hash>        # safely undo a commit that's already pushed
Key Takeaway

Git is essential for version control. GitHub makes collaboration and backup easy.

Test Your Knowledge - Take Quiz