GitHub Fundamentals: Basics and Rollback Strategies πŸ“πŸ”„βͺ

Bhargav Teja
3 min readJun 4, 2024

--

Let’s go through the process of setting up EC2 instances, connecting to GitHub with SSH keys, deploying two different websites one after the other, and then using version control to revert to the first website i.e previous deployment️. This will help us check if `git revert` or rollback works correctly. πŸš€πŸ–₯

Step 1: Create EC2 Instances with Ubuntu AMI 🌐

  1. Launch an EC2 Instance:
    - Choose Ubuntu as the Amazon Machine Image (AMI) 🐧
    - Launch the instance and connect to it via SSH. πŸ”—

Step 2: Create SSH Keys πŸ”‘

  1. Generate SSH Keys:
    - Run the command: `ssh-keygen` πŸ”§
  2. Display the public key: `cat /home/ubuntu/.ssh/id_rsa.pub` πŸ“œ

Step 3: Connect to GitHub πŸ”—

1. Copy the SSH Key:
Copy the output of `cat /home/ubuntu/.ssh/id_rsa.pub`. πŸ“‹
2. Add SSH Key to GitHub:
Go to GitHub settings, navigate to β€œSSH and GPG keys” and paste your SSH key. πŸ’»

Step 4: Create a Repository on GitHub πŸ“

  1. Create a New Repository:
  • Name it devops88 or anything of your choice

Step 5: Clone the Repository πŸŒ€

1. Copy the SSH Link:
- Click on the β€œCode” button and copy the SSH link. πŸ”—
2. Clone the Repository:
- Open Git Bash terminal and run: `git clone [your SSH link]` πŸ“‚

Step 6: Create a Script πŸ“œ

1. Navigate to the Repository:
- Go to your cloned repository directory.
2. Create a Script:
- Create a file named website.sh` and add your deployment code for the `chillingcafe` website. πŸ’Ύ

Step 7: Set Execute Permission on the Script πŸ”’

  1. Grant Execute Permission:
sudo chmod +x website.sh

Step 8: Execute the Script and View the Website 🌐

  1. Run the Script:
    - Execute: website.sh
    2. View the Website:
    - Place the instance’s IP address in a new browser tab. 🌍

Step 9: Check and Add Files πŸ”

1. Check the Status:
- Run: `git status` to see the changes. πŸ“‹
2. Add the Script:
- Run: `git add website.sh` βž•

Step 10: Commit and Push to GitHub πŸ“€

1. Commit the Changes:
- Run: `git commit -m β€œ Deploying chilling cafe website”` πŸ“
2. Push to Repository:
- Run: `git push` πŸš€

Step 11: Deploying a New Website πŸ”„

1. Change the Script:
- Update website.sh with the deployment code for the `moso-interior` website (Another website template). ✍️

Step 12: Check and Add Changes πŸ”

1. Check the Status:
- Run: `git status` to see the changes. πŸ“‹
2. Add the Script:
- Run: `git add website.sh` βž•

Step 13: Commit and Push Updates πŸ“€

  1. Commit the Changes:πŸ“
git commit -m "Deploying moso interior website"

2. Push to Repository:πŸš€

git push

Step 14: Refresh and View Updated Website πŸ”„πŸŒ

  1. Refresh the Browser Tab:
    - View the updated `moso interior` website with the instance’s IP address. 🌍

Step 15: Reverting to the Previous Website using commit hashβͺ

  1. Revert to Previous Commit:
git log

To find the commit ID of the `chilling cafe` deployment. πŸ•΅οΈ

2. Run: `git revert [commit ID]` to undo the changes and go back to the `chilling cafe` website. ↩️

Step 16: Re-deploy the Previous Code πŸš€

  1. Execute the Reverted Script:
    - Run: website.shπŸƒ
    - View the Previous Website:
    - Refresh the browser tab to see the `chilling cafe` website again. 🌍

2. Push to Repository:
- Run: `git push` πŸ“€

And there you have it! You’ve set up EC2 instances, connected to GitHub, deployed your websites, and used the `git revert` command to switch back to a previous version. Happy coding! β˜οΈπŸš€

--

--

Bhargav Teja

πŸš€ DevOps Intern passionate about 🐧 Linux, ☁️ AWS, πŸ”§ Terraform, πŸ› οΈ Azure DevOps, 🐳 Docker, πŸ—‚οΈ Git, and πŸ’» Bash scripting.