Skip to main content

Pushing a File to a GitHub Repository

Hands-On Lab


Photo of Travis Thomsen

Travis Thomsen

Course Development Director in Content





In this Live Environment, you are a developer who is starting a new development project. Before writing any code, you need create a GitHub repository, clone it locally, add a file, commit the file, and push it to GitHub.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Pushing a File to a GitHub Repository


In this hands-on lab, we'll create a GitHub repository, clone it locally, add a file, commit the file, and push it to GitHub.


Open a terminal session, and log in to the lab server via SSH using the credentials provided on the lab page:

ssh cloud_user@<PUBLIC_IP_ADDRESS>

Then, become the root user:

sudo su -

Also, sign in to your GitHub account.

Create a GitHub Repository and Push a File to It

  1. Generate an SSH key:


    Accept the defaults.

  2. Then, enter:

    cat ~/.ssh/
  3. Copy the result.

  4. In GitHub, navigate to Settings > SSH and GPG Keys.

  5. Click New SSH Key.

  6. Paste in the key you just copied, give it a title, and click Add SSH key.

  7. Enter your password to confirm.

  8. Click the + in the top navigation, and select New repository.

  9. For Repository name, enter "new-project".

  10. Click Create repository.

  11. In the Quick setup box, select SSH.

  12. Copy it to the clipboard.

  13. In the terminal, clone the project (replacing <SSH URL> with what you just copied):

    git clone <SSH URL>
  14. Change to the project directory:

    cd new-project/
  15. Create a file:

  16. Open the file:

  17. Add the contents:

    New Development Project

    Save and exit the file.

  18. Add it to Git:

    git add .
  19. Commit the file with a commit message:

    git commit -am "Add README file"
  20. Push the changes:

    git push origin master


Congratulations on completing this hands-on lab!