Create a GitHub Repository and Upload Files To It

Create a GitHub Repository

  • Login or Create an Account with GitHub
  • Click ‘Start a Project’

  • Choose a name that is not used.
    • The box will display a green check box if it is good to use
      • I used “myawesome-project”
    • Add a description if you want
    • Select public or private
      • Private is not free
        • It costs $7 a month
    • You might want to initialize it with a README file
      • This way you can just start creating files via the website
      • Otherwise, you can just “git push” from your computer that has the files you want to upload.
    • Add a license file.
      • The license file is there for you to protect your investment of time or just to prevent any legal trouble. They have many different preached license files so you do not have to hire a lawyer.
        • For more information go here
        • I normally just choose the GNU GPLv3 (GNU General Public License v3.0)
          • This allows others to use distribute, whatever, they just cannot clone it and create “closed versions”. Closed version are not open to others to contribute and so on. This is normally something that is done to make money off of your time.
      • Click “Create Repository”

Adding Code to the Repository By Uploading Via the Web UI

  • use the website and just click “Upload files”

  • Now you can just choose files or drag and drop them.

  • Wow that’s easy, only 2 steps.
    • Now if you want a command like way to do it… see the many, many steps below.
    • It’s easier to start up with the website upload, but in the end you’ll want to do the below steps so you can use GitHub.

Adding Code By Pushing It Via SSH on Mac or Linux

Git Global Setup

  • Run the following commands to setup git if you have not already
  • Replace “username” with your GitHub username.
  • Replace “emailaddress@example.com” with your email address.
git config --global user.name "username"
git config --global user.email "emailaddress@example.com"

Uploading SSH Key to GitHub

  • To do this, you must first have an SSH Key loaded in your profile
    • Generate a Key
      • Open terminal.app or just get to a command line
        • On Mac press cmd + space
          • type ‘terminal’
          • press enter
      • See if you have a ssh key already
        • Type ls -al ~/.ssh/id_rsa.pub
mla635:~ dazfre$ ls -al ~/.ssh/id_rsa.pub
-rw-r--r--  1 dazfre  109  405 Oct 19  2015 /Users/dazfre/.ssh/id_rsa.pub
  • If you do not see the file, generate one.
    • Enter ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
      • When prompted for Enter file in which to save the key (/Users/dazfre/.ssh/idrsa):

        • Press enter for default
        • When prompt to enter a passphrase, enter a password about 8 chars, Uppercase, Lowercase, numbers, and special chars.
          • This will only be used to randomly generate extra bits or Salt so hackers cannot easily brute attack the key.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
  • And you are done.
Your identification has been saved in /Users/dazfre/.ssh/test_rsa.
Your public key has been saved in /Users/dazfre/.ssh/test_rsa.pub.
The key fingerprint is:
SHA256:32QkuEOtcsz010iHHGCW1X/3mrYXCXkUbdkj4BV1gA4 dfredrick@gmail.com
The key's randomart image is:
+---[RSA 4096]----+
|          +=+=++*|
|         =E.o+.+=|
|        + o+= =o.|
|       = + +.* .+|
|      . S . = + =|
|       o o =   o.|
|          . .  o.|
|              + .|
|             ..o |
+----[SHA256]-----+
  • Now you need to copy the contents to GitHub.
    • Still in the cmd line, type cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDHEFBm7+Jjdf3LWjl4BtPFtmjHy0/mo053+QWM9yLdoeWTyEBYao+LXoNCiWLWmhWwci26RQZ6bhr9qnUL0VN2NtOCW9NDEKD+VCCVMNJMut5dxTRFeDn37S1x/k2g8QLNMjyQii+PtQaO/dPOtS14as/2TsHAPNQRUHUhWglvCqhv1DmlF6akRRe7NrcEXccHDlzG+3tJswSJab/jnJmpdkG1Rb4DzRvsJwoYWVgexVA2APej6c3lfBz2v0Wtad3HOCpAki1J5dyIhQBh8Us0CRntzCJVs5cYgb9H5+oZkdmlHSdK3RiNGtN+Z/nByzSSJyYuAJJuHfEvkXAolcCsJmAlNTH1/pqozf14XnIosC3YpCUc5PRkTBE7zsublCZna64zK4pS9tF8AIW/rmvSQ2pZO7J+yrc24I6z0f1fj41hDdn6bIFJMDSvDGCG5sdkJ3Yd/sdNYUD10zvmLVEjpOtP/uDlpQ2LIUl+QGDO8hNC92/5NDwNJMXQpBVxZoy21SQ4mw5RQ9nU72yzULiAk2BgT+IypZwBdccJdPtSvFClSXqXbUtz9MJct1FWvGOXcuBKe4cJ8gisUcBt2n8iu3OUy9C+WO1BMahWMiET1hCvf7tgIglfnA8WcybfVnirhIVYO3bl3rpBbs4CJEFUhx9UOURATiwEL7LCUwVpXQ== dfredrick@gmail.com
  • Now copy what the command line outputted to your clipboard
    • Go the GitHub and login
    • Click the odd looking square (avatar icon), and select “your profile”, next to the bell and plus sign.
    • Click “Edit profile”
    • Click “SSH and GPG keys”
    • Click “new SSH key”

  • Give it a title, like “my SSH Key for Mac Pro”
    • Paste in the output from cat ~/.ssh/id_rsa.pub that’s in your clipboard
    • Click “Add SSH Key”

Uploading Your Files with Git Push

  • Now you can git push your files to the repository with the following commands.
  • Replace “existing_folder” with the location where the files are that you want to upload or git push to GitHub.
  • Replace “username” with your username
  • Replace “projectname” with the name of your project you created.
cd existing_folder
git init
git remote add origin git@GitHub.com:username/projectname.git
git add .
git commit -m "Initial commit"
git push -u origin master

About Daniel Fredrick

Technology enthusiast, Programmer, Network Engineer CCIE# 17094

View all posts by Daniel Fredrick →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.