You will be using Github individually and collaboratively. We will set up your Cloud9 EC2 to be able to communicate with your Github account. You'll be able to copy code from a remote source (Github) and make changes to it on your personal virtual machine (Cloud9).
FWBAT...
- Clone Github repositories through their Cloud 9 Environment.
- Clone via HTTP and SSH.
- Push to and pull from a Github repository.
Create a Github Account. If you already have one, you can skip to the next step.
- Open up your Cloud9 environment. Run the following lines in the terminal, replacing the username and email with your Github username and email:
git config --global user.name "Your Github Username"
git config --global user.email "Your Github Email Address"
git config --global credential.helper store
- Confirm that the configuration was successful by running
git config --global user.name
. The terminal should print out your name. Next, rungit config --global user.email
. The terminal should print our your email address.
- Navigate to Github in the browser and log in. ON the left, click the button to create a new repository.
- Name your repository
my-first-repo
. Choose to add a README.md file. Create the repository.
While we're configuring GitHub, we should add a new SSH key.
-
First, check if you already have an SSH key by running
cat ~/.ssh/id_rsa.pub
. If the terminal prints out a long string of characters starting with ssh-rsa, you've already got a key. -
If the running previous step printed "No such file or directory", then run
ssh-keygen
to create a key. Leave everything blank and press enter for the default location and no passphrase. You should be prompted to select a file and passphrase for your new key. Leave everything blank and press enter for the default location and no passphrase. If you’re asked if you want to overwrite, then you already have an SSH key, and you do not want to overwrite it. If you've done every correctly, you should be something like this printed to your terminal:
Run cat ~/.ssh/id_rsa.pub
in your terminal. Copy the output (starting from ssh-rsa
). You'll need it for the next step
- Navigate to the homepage of Github in your browser. Go to your account settings:
Click "SSH and GPG Keys":
Click the "New SSH key" button:
Put whatever you want for the title, but preferably something related to C9 since that's the machine that has this key. Paste the key in the text area and click "Add SSH key".
- Go back to your repository on Github. Then, click on the Code button and make sure the pop-up has "SSH" underlined and selected. The url should start with
git@github.com:...
. If this is not the case, click the link that saySSH
. Copy that URL in the text box.
-
Back in your Cloud9 terminal,
cd
into yourUnit-0
folder and clone down the project usinggit clone <ssh_url>
, using the URL you copied from the previous step. If asked, "Are you sure you want to continue connecting", typeyes
. Then change directory into your projectcd my-first-repo
or whatever you named your repository. -
Once your repo can been cloned down, use the Cloud9 IDE to update the
README.md
inside of yourmy-first-repo
project. Add a 3-4 sentence bio about yourself. Be sure to save the file. -
Push the changes back up to Github using best practices. In the terminal, run:
git status
git add README.md
git commit -m "added bio"
git push
- Go back to Github to view your repository in the browser. Refresh the page and confirm that you see your newly added bio!