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
sec335
and 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 GitHubcat ~/.id_rsa.pub
Copy the contents of the folder above
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

Now follow the commands below to finish setting up your repo:
If you are using windows, you may have to install git. You can do that at this website --> https://git-scm.com/downloads/win
once downloaded, you will have an app called Git Bash that will open a terminal you can push files to.
echo "# test" >> README.md
git init
git add . -v
git add README.md
On the first time you set up your repo, you will need to set your username and email
git config --global user.email user@gmail.com
git config --global user.name "username"
git commit -m "first commit"
git branch -M main
git add origin git@github.com:username/test.git
//for windows do git remote add origin git@github.com:username/test.git
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:
git add origin git@github.com:username/test.git
git push -u origin main
git add .
git commit -m "message"
git push
Your repo should now be set up! You can use the following commands to push new files to the repo when you make them.
If you have 2 repos on your machine, and you have made changes in both, you have to do the commands below in each directory for the scripts to be uploaded.
git add .
git commit -m "message"
git push
If you make any changes in your github repo in the web browser you will need to do git pull
so that the one on your machine syncs up with the changes you made.
Addtional Resources
Last updated