Create a New Project and Push Code

In this section, you will create a new repository in your personal GitHub account to host the application codebase. You will disconnect your local working copy on the Amazon EC2 build instance from the template, configure authentication using the modern GitHub CLI, and push your customized codebase to the main branch.


Step 1: Create a new repository on GitHub

  1. Log in to your GitHub account.

  2. In the top-right corner, click your profile photo and select Your repositories.

  3. On the repositories page, click the green New button.

    GitHub repositories page

  4. Configure the repository creation form:

    • Repository name: Enter aws-fcaj-container-app
    • Description (optional): Enter a brief description such as Containerized web application deployment with Amazon ECS and GitHub Actions
    • Visibility: Select Public
    • Initialize this repository with: Leave all options unchecked (Add a README file, Add .gitignore, and Choose a license), as you will push an existing project from your EC2 build instance.

    Create a new repository form

  5. Click Create repository.

    Empty repository quick setup page

Selecting Public visibility provides unlimited free GitHub Actions runner minutes for standard Linux workflows. If you choose Private, ensure your GitHub account has remaining monthly runner minutes allocated.


Step 2: Detach from upstream Git repository on EC2

The local repository on your EC2 build instance is currently linked to the instructor upstream Git repository. To start a fresh commit history and point origin to your newly created repository, remove the existing Git tracking directory.

  1. Connect to your Amazon EC2 build instance.

  2. Navigate to the project root directory:

    cd ~/aws-fcaj-container-app
    
  3. Remove the legacy Git directory:

    sudo rm -rf .git
    

    Remove legacy Git tracking directory


Step 3: Generate a GitHub personal access token

GitHub requires token-based authentication or SSH keys for Git operations over HTTPS; standard account passwords are not accepted. In this step, you generate a personal access token (classic) to authenticate the GitHub CLI.

  1. In GitHub, click your profile photo in the top-right corner and select Settings.

    • Scroll to the bottom of the left sidebar menu and click Developer settings.
    • Expand Personal access tokens and select Tokens (classic).

    Personal access tokens classic menu

  2. Click Generate new token, then choose Generate new token (classic).

    Generate new token option

  3. Configure the token parameters:

    • Note: Enter GitHub CLI
    • Expiration: Select 30 days (or your preferred duration)
    • Select scopes: Check the following required permissions:
      • repo (Full control of private repositories)
      • workflow (Update GitHub Action workflows)
      • admin:org (Read and write org and team membership, read and write org projects)
      • project (Full control of project boards)
      • Scroll to the bottom of the page and click Generate token. Token scope configuration
  4. Click the copy icon next to the generated token to copy it to your clipboard.

Copy generated personal access token

GitHub displays personal access tokens only once upon creation. If you leave or refresh this page without saving the token, you must delete it and generate a new one. Never expose access tokens in public repositories or unencrypted configuration files.


Step 4: Install and authenticate GitHub CLI on EC2

  1. On your Amazon EC2 terminal, install the GitHub CLI package:

    sudo apt install gh -y
    
  2. Run the interactive authentication command:

    gh auth login
    
  3. Complete the interactive prompts with the following choices:

    • What account do you want to log into?: Select GitHub.com
    • What is your preferred protocol for Git operations?: Select HTTPS
    • Authenticate Git with your GitHub credentials?: Select Y (Yes)
    • How would you like to authenticate GitHub CLI?: Select Paste an authentication token
    • Token: Paste the personal access token you generated in Step 3.

    GitHub CLI interactive authentication

Verification checkpoint

Verify your GitHub CLI authentication status:

gh auth status

Expected terminal output:

github.com
  ✓ Logged in to github.com account <your-username> (keyring)
  - Active account: true
  - Git operations protocol: https
  - Token: ghp_************************************
  - Token scopes: 'admin:org', 'project', 'repo', 'workflow'

Step 5: Initialize Git and push source code to GitHub

Initialize a fresh Git repository, stage all files, set the default branch name to main, link your remote GitHub repository, and push the codebase.

  1. Ensure you are in the application root directory:

    cd ~/aws-fcaj-container-app
    
  2. Execute the Git setup and push sequence:

    git init
    git add .
    git commit -m "Initial commit for containerized app"
    git branch -M main
    git remote add origin https://github.com/<your-username>/aws-fcaj-container-app.git
    git push -u origin main
    

    Push repository source code to GitHub

  3. Check your remote tracking configuration and local tree status:

    git remote -v
    git status
    

    Expected terminal output:

    origin  https://github.com/<your-username>/aws-fcaj-container-app.git (fetch)
    origin  https://github.com/<your-username>/aws-fcaj-container-app.git (push)
    On branch main
    Your branch is up to date with 'origin/main'.
    nothing to commit, working tree clean