How to Push Code to Github

Set up

  • Go to wherever you want to clone your git repo

    • if you have a folder on your machine called sec335and want to push everything in that folder into your repo, you have to make sure you are in the directory before you do any commands.

  • Go back to your github account, and make a new repository with the name of the directory you made in your command line.

  • DONT add a README file

The reason we don't set a README file is so that we get the screen below in our repo. This screen gives us the set-up commands and our SSH URL.

In your command line:

  • run ssh-keygen to make an SSH key to identify yourself to GitHub

  • cat ~/.id_rsa.pub

  • Copy the contents of the folder above

circle-info

If you are using windows follow these steps:

  • ssh-keygen -t rsa -b 4096

  • You will be promoted to enter a file to save the key to, press enter to save it to the default file C:\Users\hannelore/.ssh/id.rsa

Go back to your github profile:

  • Go to Profile > Settings > SSH and GPG Keys > New SSH Key

    • Copy the contents of the .id_rsa.pub file into the Key box below

    • Give the key a title so you know which machine you are using it on

circle-info

You only need to do the SSH key process once per machine. Once you do, you can push anything to your github, its not specific to one repo.

Now follow the commands below to finish setting up your repo:

circle-exclamation

On the first time you set up your repo, you will need to set your username and email

  • In the screenshot below you will need to click on SSH instead of HTTPS

Copy the SSH link you see in your github and use it with the command below:

Your repo should now be set up! You can use the following commands to push new files to the repo when you make them.

circle-exclamation
circle-exclamation

Addtional Resources

Last updated