This is a beginner-friendly, step-by-step; Git + GitHub walkthrough you can follow on an AWS EC2 instance running Amazon Linux 2023 (SSH access).
By the end, you will be able to:
- Understand Git vs GitHub
- Create a clean project workspace
- Install and configure Git locally per repo (no global settings)
- Generate and add a GitHub SSH key (with troubleshooting)
- Fork an upstream repository
- Clone your fork to your VM
- Create a feature branch
- Edit
index.html+style.css - Commit changes, push to your fork, and open a Pull Request
- Understand what a PR does (and does not do) to the original repo
- Optionally publish your page under Nginx as
/your-github-project/alongside an existing React deployment
Learning context: This walkthrough supports self-paced learning and collaboration workflows using open-source materials.
Table of Contents
- Prerequisites
- Git vs GitHub
- Step 1 — Connect to Your VM
- Step 2 — Install Git (Amazon Linux 2023)
- Step 3 — Create a Clean Project Workspace
- Step 4 — Local Git Config (Per Repository Only)
- Step 5 — Generate a GitHub SSH Key
- Step 6 — Fork the Assignment Repo on GitHub
- Step 7 — Clone Your Fork to the VM
- Step 8 — Add Upstream (What It Does)
- Step 9 — Create a Feature Branch
- Step 10 — Make Your Changes (index.html + style.css)
- Step 11 — Stage, Commit, and Review History
- Step 12 — Push Your Branch to GitHub
- Step 13 — Open a Pull Request (PR)
- Step 14 — Keep Your Fork Updated (Sync Upstream)
- Debugging Example: UI Broke After CSS Update
- Optional: Publish Under Nginx as /your-github-project/
- Key Takeaways
- Credits
Prerequisites
You need:
- An AWS EC2 instance running Amazon Linux 2023
- SSH access to that instance
- A GitHub account
- Basic terminal comfort (copy/paste commands is fine)
Optional (but helpful):
- A text editor like
nano(I used vim)
Git vs GitHub
Git: a version control tool that runs on your computer (or VM). It tracks changes to files over time.
GitHub: a website that hosts Git repositories online so you can collaborate, share, and open pull requests.
Simple analogy:
- Git = the save/history engine
- GitHub = the online place where projects live and collaboration happens
Step 1 — Connect to Your VM
From your local computer, connect to your EC2 instance:
ssh -i /path/to/your-key.pem ec2-user@YOUR_PUBLIC_IP
What the pieces mean:
-
ssh= secure shell (remote terminal) -
-i ...pem= your EC2 private key file -
ec2-user@...= the username and server address
Once logged in, you’re working on the VM.
Step 2 — Install Git (Amazon Linux 2023)
Update system packages:
sudo dnf update -y
Install Git:
sudo dnf install -y git
Verify:
git --version
Flag notes:
-
sudo= run as admin -
dnf= Amazon Linux 2023 package manager -
-y= auto “yes” to prompts
Step 3 — Create a Clean Project Workspace
Create a parent folder for all repos:
mkdir -p ~/projects
cd ~/projects
Important rule:
-
Do not run
git initin~/projects - Each repo should be its own separate folder with its own
.gitdirectory
Step 4 — Local Git Config (Per Repository Only)
You asked an important question: “Global vs local?”
- Global config applies to all repos on this VM user account
- Local config applies only to one repo
For this walkthrough, we use local config only to keep things isolated.
You can only set local config after a repo exists (after git init or git clone).
We’ll do it after cloning in Step 7.
Step 5 — Generate a GitHub SSH Key
Should you add a passphrase?
Recommended: Yes (especially on cloud VMs). A passphrase protects your private key if the VM is compromised.
Generate an SSH key:
ssh-keygen -t ed25519 -C "YOUR_EMAIL@example.com"
What flags mean:
-
-t ed25519= modern, secure key type -
-C= a label/comment (helps identify the key)
When prompted for a file location:
- Press Enter to accept the default (
~/.ssh/id_ed25519)
When prompted for passphrase:
- Set a passphrase (recommended), then confirm it
Start the SSH agent and add your key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Copy the public key (this is what GitHub needs):
cat ~/.ssh/id_ed25519.pub
Now on GitHub:
- Settings → SSH and GPG keys → New SSH key
- Key type: Authentication Key
- Paste the full line from
.pub
Test connectivity:
ssh -T git@github.com
Expected result:
- A message saying you authenticated successfully (GitHub does not provide shell access)
Common Error: “Key is invalid…”
If GitHub says:
“Key is invalid. You must supply a key in OpenSSH public key format”
It almost always means one of these:
- You pasted the private key by accident (wrong)
- You didn’t paste the
.pubkey - You included extra characters (like the terminal prompt)
Fix checklist:
- Make sure you copied only the output of:
cat ~/.ssh/id_ed25519.pub
- It should be a single line starting with:
ssh-ed25519 ...
- Do NOT paste:
-
id_ed25519contents (private key) -
$prompts or extra spaces
-
Step 6 — Fork the Assignment Repo on GitHub
Open the upstream repository in your browser:
Click:
- Fork (top right)
This creates your own copy under your account (example):
https://github.com/yourusername/Week-2---Git-GitHub-Assignment
Why forks matter:
- You can change your fork freely
- You can open a PR to propose changes back to the original
Step 7 — Clone Your Fork to the VM
In your VM terminal:
cd ~/projects
git clone git@github.com:yourusername/Week-2---Git-GitHub-Assignment.git
cd Week-2---Git-GitHub-Assignment
Explanation:
-
git clonedownloads the repo and creates a folder - It also sets a remote called
originautomatically
Check remotes:
git remote -v
You should see origin pointing to your fork.
Set local git config in THIS repo
Now that you’re inside the repo, set local config:
git config user.name "Your Username"
git config user.email "yourusername@users.noreply.github.com"
Verify local settings:
git config --list --local
Step 8 — Add Upstream (What It Does)
Add the original repo as upstream:
git remote add upstream https://github.com/pravinmishraaws/Week-2---Git-GitHub-Assignment.git
git remote -v
What this does:
-
origin= your fork (where you push) -
upstream= original repo (where you fetch updates)
It does NOT:
- merge changes automatically
- change the original repo
- give you permission to push to upstream
Step 9 — Create a Feature Branch
Create and switch to a new branch:
git switch -c your-branch-name
Why branch?
- Keeps your changes separate from the default branch
- Makes PRs clean and reviewable
How to Confirm You’re on the Right Branch
Use any of these:
git status
Look for: On branch ...
Or:
git branch
The branch with * is your current branch.
Or quick output:
git branch --show-current
Why You Might See master Instead of main
Some repos use master as the default branch instead of main.
This is normal.
There is no functional difference for this assignment.
Use whatever default branch exists in your repo.
Step 10 — Make Your Changes (index.html + style.css)
Edit your files:
vim index.html
vim style.css
Vim basics:
- When you first open a file, Vim is in command mode (you cannot type yet)
- Press
ito enter insert mode (so you can type and edit) - Press
Escto leave insert mode - Type
:wthen press Enter to save - Type
:qthen press Enter to quit - Type
:wqthen Enter to save and quit - Type
:q!then Enter to quit without saving
Make your updates (student details + theme).
Step 11 — Stage, Commit, and Review History
Check what changed:
git status
Preview changes line-by-line:
git diff
Stage (add to the “next commit”):
git add index.html style.css
Commit (save snapshot):
git commit -m "Your descriptive commit note"
View history:
git log --oneline
Step 12 — Push Your Branch to GitHub
Push your branch:
git push -u origin your-branch-name
What -u does:
- sets tracking so next time you can run
git pushwithout extra arguments
Step 13 — Open a Pull Request (PR)
On GitHub, go to your fork repo page.
You should see a prompt like:
- “Compare & pull request”
Create a PR:
- Base repository:
pravinmishraaws/Week-2---Git-GitHub-Assignment - Base branch:
mainormaster(whatever the upstream uses) - Compare branch: your branch (
your-branch-name)
Does a PR change the original repo?
No.
A PR is a request to merge.
The upstream repo does not change until:
- the maintainer approves and merges it
Suggested PR Description
You can paste this:
This pull request is for learning purposes only.
The goal is to practice the GitHub pull request workflow, understand how forks and branches are compared, and learn how collaboration works in a real repository. The changes are intentionally simple and focused on hands-on learning rather than introducing new features.
Thank you, Pravin, for providing open-source learning materials and repositories that make it easier to learn Git and GitHub through real practice.
Step 14 — Keep Your Fork Updated (Sync Upstream)
If upstream changes later:
git fetch upstream
Merge upstream changes into your default branch (example uses master):
git switch master
git merge upstream/master
Push updates to your fork:
git push origin master
Notes:
- Use
mainif your repo uses main instead of master. -
fetchis safe because it downloads without changing files until you merge.
Debugging Example: UI Broke After CSS Update
Scenario:
- You update
style.css - The page layout looks broken
Find recent commits that touched the file:
git log -- style.css
Compare changes:
git diff
If you know the commit hash that introduced the issue:
git diff <good_commit_hash> <bad_commit_hash>
Why this matters (DevOps mindset):
- You may not be the original author
- You still need to identify what changed and when
- Git history is a debugging tool, not just “backup”
Optional: Publish Under Nginx as /your-github-project/
This is optional, but it’s a great real-world deployment skill:
- serve your Git assignment page alongside your React app via Nginx
Reference article (React + Nginx deployment on Amazon Linux):
https://dev.to/ldwit/deploying-a-react-app-with-nginx-on-aws-amazon-linux-beginner-walkthrough-3h76
Confirm your Nginx root
Run:
sudo nginx -T | grep -i root
In the example setup, the active root was:
/var/www/react-app/current
Create a folder for your static page
sudo mkdir -p /var/www/react-app/current/your-github-project
Copy your assignment files into that folder
From your repo folder:
sudo cp index.html style.css /var/www/react-app/current/your-github-project/
Fix permissions (avoid 403 errors)
sudo chmod -R 755 /var/www/react-app/current/your-github-project
Reload Nginx safely
sudo nginx -t
sudo systemctl reload nginx
Test it
Open:
http://YOUR_PUBLIC_IP/your-github-project/
Key Takeaways
- Git tracks history in commits
- Staging (
git add) is your “commit preview” - Branches keep work isolated
- Fork + PR is the safe collaboration workflow
- A PR does not change upstream until merged
- Git commands like
loganddiffhelp debug issues quickly - Nginx can serve static pages alongside apps for portfolio demos
Credits
- Pravin Mishra -- open-source DevOps learning materials and the DMI community
Self-paced practice and notes from a real Amazon Linux 2023 VM workflow
-
Udemy Course -- DevOps for Beginners: Docker, Kubernetes, Cloud & CI/CD (4 Projects)
-
GitHub Repository
Top comments (0)