DEV Community

Cover image for From EC2 to GitHub: Connecting Your Cloud Code Like a Pro
Adesola Kehinde
Adesola Kehinde

Posted on

From EC2 to GitHub: Connecting Your Cloud Code Like a Pro

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

Image description
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.

Image description

πŸ’‘ A GitHub repository is like a magic folder that tracks every change in your project.


🌱 Step 3: Initialize Local Git Repo

git init
Enter fullscreen mode Exit fullscreen mode

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

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

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.

Image description

πŸ” 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
Enter fullscreen mode Exit fullscreen mode

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)