Hey DevOps explorer! 👋 Today we're diving into Project 2 of my 7-Day DevOps Challenge, where I connect my Java web app hosted on AWS EC2 to GitHub using Git. By the end of this post, you’ll understand how to:
✅ Install Git on your EC2 instance
✅ Set up a GitHub repo
✅ Track and commit code
✅ Push code from EC2 to GitHub using a personal access token
🛠 Why This Matters
Version control is a must-have skill for any developer. Whether you're flying solo or collaborating on a team, Git and GitHub help you keep your code safe, traceable, and easy to manage.
☁️ Step 1: Install Git on EC2
sudo dnf update -y
sudo dnf install git -y
Git is a version control tool that tracks your code changes. Installing it lets you start managing your code history on the server itself.
🔐 Step 2: Set Up GitHub & Create a Repo
Head to GitHub, create a free account (if you haven’t), and start a new repository — this is where your code will live in the cloud.
💡 A GitHub repository is like a magic folder that tracks every change in your project.
🌱 Step 3: Initialize Local Git Repo
git init
This sets up Git inside your project folder on EC2, creating a master
branch.
✍️ Step 4: Track and Commit Code
git add .
git commit -m "Initial commit"
git add .
stages your files, and git commit
saves the snapshot. Think of it as telling Git, “Hey, these are the changes I care about.”
🔗 Step 5: Link to GitHub and Push
First, copy the HTTPS URL from your GitHub repo. Then:
git remote add origin https://github.com/your-username/your-repo-name.git
git branch -M master
git push -u origin master
Oops! Git might ask for your username and password, but GitHub no longer accepts passwords.
🔑 Step 6: Use a GitHub Token Instead
Go to GitHub → Settings → Developer Settings → Personal Access Tokens.
Generate a token with repo
access and copy it. Use it when Git asks for a password.
🔐 A GitHub token is a secure key that acts like a password for Git operations.
💡 Bonus: Editing & Pushing Again
I updated index.jsp
, then ran:
git add .
git commit -m "Updated homepage"
git push
And just like that—my changes appeared live in the GitHub repo. Magic!
🔁 What I Learned
Services used: EC2, Git, GitHub, VS Code
Concepts learned: version control, repo setup, staging/commits, GitHub tokens
⏱ Project Reflection
This project took me around 2 hours. The trickiest part? Setting up GitHub authentication.
The best part? Watching my code go live in my repo with one command.
This is just the beginning. Stay tuned for Project 3 tomorrow—CI/CD, here we come! 💥
Top comments (0)