GitHub Essentials
What is GitHub?
GitHub is a cloud-based hosting platform for Git repositories. While Git is the tool that tracks your code history on your computer, GitHub lets you store that history online — making it accessible from anywhere and shareable with anyone.
But GitHub is much more than just a backup. It's a social coding platform where millions of developers collaborate on projects, discover open-source code, showcase their work to employers, and contribute to software that powers the world.
GitHub gives you: remote repository hosting (your code in the cloud), collaboration tools (pull requests, code review, issues), CI/CD pipelines (GitHub Actions), project management (Projects, Milestones), and your developer portfolio (your GitHub profile is your resume).
Creating a GitHub Account & Repository
Head to github.com and sign up for a free account. Choose your username carefully — it becomes part of your GitHub profile URL (github.com/yourusername) and will be seen by employers.
Creating Your First Repository
Once signed in, click the + icon in the top right → New repository. You'll need to configure a few options:
Connecting Local to Remote
After creating a GitHub repo, you need to link your local Git repository to it. The remote is given an alias — by convention it's called origin.
# Add the remote (replace with your actual repo URL) git remote add origin git@github.com:username/my-repo.git # Verify the remote was added git remote -v # Output: # origin git@github.com:username/my-repo.git (fetch) # origin git@github.com:username/my-repo.git (push) # List all remotes git remote # Remove a remote (if you need to change it) git remote remove origin # Change a remote URL git remote set-url origin git@github.com:username/new-repo.git
SSH vs HTTPS
There are two ways to connect to GitHub: SSH and HTTPS. HTTPS is simpler to set up initially but requires entering credentials. SSH uses cryptographic keys and is the professional standard — once set up, you never type a password again.
git@github.com:user/repo.git
https://github.com/user/repo.git
SSH Key Setup
SSH keys work like a lock and key. You generate a key pair — a private key that stays on your machine and a public key that you share with GitHub. When you connect, GitHub verifies your private key matches the public key on file. You never send a password.
# Step 1: Generate a new SSH key (use your GitHub email) ssh-keygen -t ed25519 -C "you@email.com" # Press Enter to accept default location (~/.ssh/id_ed25519) # Enter a passphrase (optional but recommended) # Step 2: Start the SSH agent eval "$(ssh-agent -s)" # Step 3: Add your private key to the agent ssh-add ~/.ssh/id_ed25519 # Step 4: Copy your PUBLIC key to clipboard cat ~/.ssh/id_ed25519.pub # (Copy the output — starts with ssh-ed25519...) # Step 5: Test your connection to GitHub ssh -T git@github.com # Expected: Hi username! You've successfully authenticated...
id_ed25519.pub), give it a title like "My Laptop", and click Add SSH key. Done — that machine can now authenticate without a password.Your First Push
With your remote connected and SSH key set up, you're ready to push your local commits to GitHub. The first push uses -u to set up upstream tracking — after that, a simple git push is enough.
# First push: -u sets up tracking (do this once per branch) git push -u origin main # After that, just: git push # Pull remote changes to your local repo git pull origin main # Or just: git pull # Fetch without merging (inspect before applying) git fetch origin git diff main origin/main # see what's different git merge origin/main # then apply
git fetch is like pull but safer — it downloads changes without applying them, so you can review first.Cloning Repositories
git clone downloads a complete copy of a remote repository — including all commits, branches, and history — to your local machine. It's how you start working on any existing project.
# Clone into a new folder (folder name = repo name) git clone git@github.com:username/my-repo.git # Clone into a specific folder name git clone git@github.com:username/my-repo.git my-project # Clone via HTTPS git clone https://github.com/username/my-repo.git # What clone does automatically: # 1. Creates a local folder # 2. Initializes Git inside it # 3. Adds 'origin' remote pointing to the source # 4. Downloads all commits, branches, tags # 5. Checks out the default branch (usually main)
Clone vs Fork
Clone creates a local copy of any repo on your machine. You can push back if you have write access. Fork creates your own GitHub copy of someone else's repo. Forks are used when you want to contribute to a project you don't own — you fork it, make changes in your copy, then send a Pull Request to the original. We'll cover forks in depth in Lesson 6.
GitHub README — Your Project's Front Door
The README.md file is the first thing people see when they visit your repository. A great README instantly communicates what the project does, how to install it, and how to use it. It's written in Markdown — a lightweight markup language.
# Project Name A one-line description of what this project does. ## ✨ Features - Feature one - Feature two - Feature three ## 🚀 Quick Start ```bash git clone https://github.com/username/project.git cd project npm install npm start ``` ## 📸 Screenshot  ## 🛠️ Built With - JavaScript - Node.js - GitHub Actions ## 📄 License MIT © 2025 Your Name
. They make your project look professional and give visitors instant info at a glance.git clone do?-u flag do in git push -u origin main?git clone and a fork?1. Create a GitHub repository called
my-first-repo (public, no README)2. On your machine:
mkdir my-first-repo && cd my-first-repo && git init3. Connect it:
git remote add origin git@github.com:YOURUSERNAME/my-first-repo.git4. Create a
README.md with your name and what you're learning5. Stage & commit:
git add . && git commit -m "docs: add initial README"6. Push:
git push -u origin main7. Visit your GitHub repo URL and verify the README appears
💡 Show hints
- Make sure SSH is set up first — run
ssh -T git@github.comto test - If you get a "main vs master" error, run
git branch -M mainbefore pushing - Copy the exact SSH URL from the GitHub repo page (green Code button → SSH tab)
- If you initialized with a README on GitHub, you may need to
git pull --rebase origin mainfirst