DEV Community

LaTerral Williams
LaTerral Williams

Posted on

Git & GitHub for Beginners (Amazon Linux 2023): Fork, Branch, Commit, Pull Request (Walkthrough)

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

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Install Git:

sudo dnf install -y git
Enter fullscreen mode Exit fullscreen mode

Verify:

git --version
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Important rule:

  • Do not run git init in ~/projects
  • Each repo should be its own separate folder with its own .git directory

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Copy the public key (this is what GitHub needs):

cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 .pub key
  • You included extra characters (like the terminal prompt)

Fix checklist:

  1. Make sure you copied only the output of:
   cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode
  1. It should be a single line starting with:
    • ssh-ed25519 ...
  2. Do NOT paste:
    • id_ed25519 contents (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
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • git clone downloads the repo and creates a folder
  • It also sets a remote called origin automatically

Check remotes:

git remote -v
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Verify local settings:

git config --list --local
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Look for: On branch ...

Or:

git branch
Enter fullscreen mode Exit fullscreen mode

The branch with * is your current branch.

Or quick output:

git branch --show-current
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Vim basics:

  • When you first open a file, Vim is in command mode (you cannot type yet)
  • Press i to enter insert mode (so you can type and edit)
  • Press Esc to leave insert mode
  • Type :w then press Enter to save
  • Type :q then press Enter to quit
  • Type :wq then 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
Enter fullscreen mode Exit fullscreen mode

Preview changes line-by-line:

git diff
Enter fullscreen mode Exit fullscreen mode

Stage (add to the “next commit”):

git add index.html style.css
Enter fullscreen mode Exit fullscreen mode

Commit (save snapshot):

git commit -m "Your descriptive commit note"
Enter fullscreen mode Exit fullscreen mode

View history:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

Step 12 — Push Your Branch to GitHub

Push your branch:

git push -u origin your-branch-name
Enter fullscreen mode Exit fullscreen mode

What -u does:

  • sets tracking so next time you can run git push without 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: main or master (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.
Enter fullscreen mode Exit fullscreen mode

Step 14 — Keep Your Fork Updated (Sync Upstream)

If upstream changes later:

git fetch upstream
Enter fullscreen mode Exit fullscreen mode

Merge upstream changes into your default branch (example uses master):

git switch master
git merge upstream/master
Enter fullscreen mode Exit fullscreen mode

Push updates to your fork:

git push origin master
Enter fullscreen mode Exit fullscreen mode

Notes:

  • Use main if your repo uses main instead of master.
  • fetch is 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
Enter fullscreen mode Exit fullscreen mode

Compare changes:

git diff
Enter fullscreen mode Exit fullscreen mode

If you know the commit hash that introduced the issue:

git diff <good_commit_hash> <bad_commit_hash>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

Fix permissions (avoid 403 errors)

sudo chmod -R 755 /var/www/react-app/current/your-github-project
Enter fullscreen mode Exit fullscreen mode

Reload Nginx safely

sudo nginx -t
sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

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 log and diff help debug issues quickly
  • Nginx can serve static pages alongside apps for portfolio demos

Credits

Top comments (0)