Menu
AWS Cloud9
User Guide

GitHub Sample for AWS Cloud9

This sample enables you to set up an AWS Cloud9 development environment to interact with a remote code repository in GitHub. For more information about GitHub, see the GitHub and GitHub Help websites.

Note

This sample assumes you already have the AWS Cloud9 IDE for your AWS Cloud9 development environment open in your web browser, and that you're using an AWS Cloud9 EC2 development environment that is connected to an Amazon EC2 instance running Amazon Linux. In you're using a different operating system or using an AWS Cloud9 SSH development environment, you might need to adapt this sample's instructions to correctly install and configure this sample's required tools. To create an environment, see Creating an Environment.

When you're using this sample, be sure you're signed in to AWS with the AWS account ID and name and password of the user you created or identified in Team Setup.

Creating this sample may result in charges to your AWS account. These include possible charges for services such as Amazon EC2. For more information, see Amazon EC2 Pricing.

Start with the following step, depending on what you already have.

Do you have a GitHub account? Do you have a GitHub repository? Do you have Git installed? Start with this step

No

--

--

Step 1: Create a GitHub Account

Yes

No

--

Step 2: Create a GitHub Repository

Yes

Yes

No (or Not Sure)

Step 3: Install Git in Your Environment

Yes

Yes

Yes

Step 4: Clone the Remote Repository into Your Environment

Step 1: Create a GitHub Account

If you already have a GitHub account, skip ahead to Step 2: Create a GitHub Repository.

To create a GitHub account, see Join GitHub on the GitHub website.

Step 2: Create a GitHub Repository

If you already have a GitHub repository, skip ahead to Step 3: Install Git in Your Environment.

To create the repository, see Create A Repo on the GitHub Help website.

Step 3: Install Git in Your Environment

In this step, you use the AWS Cloud9 IDE to install Git in your environment so that you can clone your remote repository into the environment later.

If you already have Git installed in your environment, skip ahead to Step 4: Clone the Remote Repository into Your Environment. To check whether you already have Git installed, run the git --version command as described in this step.

  1. With your environment open, in the AWS Cloud9 IDE, start a new terminal session, if one isn't already started. (To start a new terminal session, on the menu bar, choose Window, New Terminal.)

  2. Check whether Git is already installed. In the terminal, run the git --version command. If Git is installed, the version number is displayed, for example, git version N.N.N . The installed version must be 1.7.9 or later. If it is, skip ahead to step 4 in this procedure to set your Git name and email address.

  3. To install Git, see Git Downloads on the Git website. For example, for an EC2 environment running Amazon Linux, run these three commands in the terminal, one at a time, to install Git.

    Copy
    sudo yum -y update # Install the latest system updates. sudo yum -y install git # Install Git. git --version # Confirm Git was installed.
  4. Set your Git name and email address. In the terminal, run these two commands, one at a time, substituting your Git name and email address for USER_NAME and EMAIL_ADDRESS .

    Copy
    git config --global user.name "USER_NAME" git config --global user.email EMAIL_ADDRESS

Step 4: Clone the Remote Repository into Your Environment

In this step, you use the AWS Cloud9 IDE to clone the remote repository in GitHub into your environment.

To clone the repository, see Cloning a Repository on the GitHub website.

Note

The rest of this sample assumes the current working directory that you clone the repository into is the environment root directory. If you clone it somewhere else, substitute that location wherever you see /YOUR_CLONED_REPO_NAME .

Step 5: Add Files to the Repository

In this step, you create three simple files in the cloned repository in your environment. Then you add the files to the Git staging area in your cloned repository, commit the staged files, and push the commit to your remote repository in GitHub.

If the cloned repository already has files in it, skip ahead to Step 6: Keep Working with the IDE and GitHub.

  1. Create a new file. On the menu bar, choose File, New File.

  2. Type the following content into the file, and then choose File, Save to save the file as bird.txt in the /YOUR_CLONED_REPO_NAME directory in your environment.

    Copy
    bird.txt -------- Birds are a group of endothermic vertebrates, characterized by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton.

    Note

    To confirm you are saving this file in the correct directory, in the Save As dialog box, choose the YOUR_CLONED_REPO_NAME folder, and be sure Folder displays /YOUR_CLONED_REPO_NAME .

  3. Create two more files, named insect.txt and reptile.txt, with the following content, saving them also in the same /YOUR_CLONED_REPO_NAME directory.

    Copy
    insect.txt ---------- Insects are a class of invertebrates within the arthropod phylum that have a chitinous exoskeleton, a three-part body (head, thorax, and abdomen), three pairs of jointed legs, compound eyes, and one pair of antennae.
    Copy
    reptile.txt ----------- Reptiles are tetrapod (four-limbed vertebrate) animals in the class Reptilia, comprising today's turtles, crocodilians, snakes, amphisbaenians, lizards, tuatara, and their extinct relatives.
  4. In the terminal, run the cd command to switch to the /YOUR_CLONED_REPO_NAME directory.

    Copy
    cd YOUR_CLONED_REPO_NAME
  5. Confirm the files were successfully saved in the /YOUR_CLONED_REPO_NAME directory by running the git status command. All three files are listed as untracked files.

    Copy
    Untracked files: (use "git add <file>..." to include in what will be committed) bird.txt insect.txt reptile.txt
  6. Add the files to the Git staging area by running the git add command.

    Copy
    git add --all
  7. Confirm the files were successfully added to the Git staging area by running the git status command again. All three files are now listed as changes to commit.

    Copy
    Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: bird.txt new file: insect.txt new file: reptile.txt
  8. Commit the staged files by running the git commit command.

    Copy
    git commit -m "Added information about birds, insects, and reptiles."
  9. Push the commit to your remote repository in AWS CodeCommit by running the git push command.

    Copy
    git push

    Note

    You are prompted for your GitHub user name and password. As you continue to work with GitHub, you may be prompted again. To keep from being prompted each time you try to interact with the remote repository in the future, consider installing and configuring a Git credentials manager. For example, you can run this command in the terminal to be prompted no sooner than every 15 minutes: git config credential.helper 'cache --timeout 900'. Or you can run this command to never be prompted again, although Git stores your credentials in clear text in a plain file in your home directory: git config credential.helper 'store --file ~/.git-credentials'. For more information, see Git Tools - Credential Storage on the Git website.

    If you use GitHub two-factor authentication, you must enter a personal access token whenever you are prompted for a password. If you enter a password instead of a personal access token, an "invalid user name or password" message is displayed, and the operation fails. For more information, see Creating a personal access token for the command line on the GitHub Help website.

    You will not see your password or personal access token whenever you enter it in the terminal. This is by design.

  10. To confirm whether the files were successfully pushed from your local copy of the repository to the remote repository, open your repository in the GitHub console, and look for the three files you just pushed.

Step 6: Keep Working with the IDE and GitHub

Use the AWS Cloud9 IDE and GitHub to keep working with your code. Here are some things to try.

  • Use the Environment window and editor tabs in the IDE to view, change, and save code. For more information, see Step 2.3: Environment Window and Step 2.4: Editor, Tabs, and Panes in the Tutorial for AWS Cloud9.

  • Use the IDE to run, debug, and build your code. For more information, see Working with Builders, Runners, and Debuggers.

  • Use Git in the terminal session in the IDE to continue pushing more code changes to the GitHub repository, as well as periodically pull code changes from others from the repository. For more information, see Pushing to a Remote and Fetching a remote on the GitHub Help website.

  • Use additional Git commands as you need them. For a list of these commands, see Git cheatsheet on the GitHub Help website.

  • If you're new to Git and you don't want to mess up your GitHub repository, experiment with a sample Git repository on the Try Git website.

  • Invite others to work on your code with you in the same environment, in real time and with text chat. For more information, see Sharing an Environment.

Step 7: Clean Up

To prevent ongoing charges to your AWS account after you're done using this sample, you should delete the environment. For instructions, see Deleting an Environment.

To delete the GitHub repository, see Deleting a Repository on the GitHub Help website.