Now that we've initialized our git project locally on our machine we can go
ahead and push this code to Github
Pushing to github comes in really useful if
you need to ask for any questions on the Q&A because you can just link to your
project source code on github and then I can take a look at the code and see if I
can figure out where the problem might be
just note that anything you push to
github will be publicly available so be careful not to commit any secret keys or
passwords with your project
okay so let's go ahead and push our project
to github
we need to start by creating a public/private key pair let's start by
typing in our terminal or git bash window LS tilde forward slash dot SSH
and hit enter just to make sure we don't have any existing keys in our SSH
directory
By default the SSH directory is where all public private SSH keys are
created on the system and this should be the same for Mac or if you're using a
Windows and you're using the git bash since we don't have any existing keys
we're going to go ahead and create a new key by typing SSH - key gen - T RSA
- B 409 6 - capital C and then our email address so I'm going to put
mark@londonappdeveloper.com
what this command does is it runs the SSH key gen
tool and then it says we want to create a new key with a type RSA that's the
type of key that we're creating and we want to create a key that is
4096 bytes
then this - C and this message here is just the comment so we
can identify what key this is for if we ever need to check it
okay so if you hit
enter it will generate the key pair and by default it will create it in your
home directory forward slash SSH and then ID RSA this is the default key for your
system and I recommend leaving this as default for this course
now you can
create an optional passphrase for your key and I always recommend creating a
passphrase this adds an extra layer of security on your key so
if somebody manages to steal the key from your computer they won't be able to
use it without the passphrase
for the purpose of this course I'm going to leave
this blank but feel free to enter a passphrase if you want to use a
passphrase to protect your key
okay now you can see that our key has been
created and we have these two new files created in our SSH directory let's
just type LS tilde forward slash dot SSH again and let's check that these
files exist
Okay so the ID RSA file here is the private key now you want to make
sure you never share the contents with this key or the file with anyone else
you want to keep this safe at all times because this is basically like your
password
the id_rsa.pub key is the public key this is the key that you can
upload to services like github in order to authenticate
okay so now that we've
generated our key let's go ahead and head over to github.com which I've
linked to in the resources and login with your account
now we need to add our
public key to our account so click on your profile here on the top right and
then click on settings
in the settings menu on the left you should see this SSH
and GPG keys so click on that and this is where we can add SSH keys to our
account so let's click new SSH key and then let's head back to our terminal or
git bash and we're going to output our public key by using this CAT or cat
command so type cat tilde forward slash dot SSH forward slash ID underscore RSA dot pub
and again remember to include the dot pub when you output the key because
you don't want to share your private key with anyone
okay when you
hit enter you should see this random string of text here ending in the
comment we provided in the - capital C part of our command here so
this is our public key now make sure you copy it right from the beginning to the
end you don't want to miss any because otherwise it won't work properly so it's from the
SSH RSA all the way to the end of our
comment here I'm going to do right click copy and then let's head over to our
github page and paste this in
okay so we've pasted the contents of the key now
let's just call the key but give the key the title of the machine that we're
authenticating with this key so in my case this is mark laptop
okay now click
add SSH key and it should add the key to our account here so you can see we've
got mark laptop and then it's got added on the 6th of April which is the day
that I added it just now
okay now that we've set up authentication we should be
able to push the project to github so let's head back to the github home page
and let's create a new project for our project
we're going to call our
repository profiles - rest - API and we can give it the description source
code for profiles rest api course
we're going to leave it as public and we're
going to uncheck or leave unchecked the initialize this repository with a readme
because we've already created these files in our project in the previous
video so let's click create repository and then this should take us to this
page which explains how we can add our remote to our local git project so we
want to use this instruction here which is push an existing repository from the
command line because we already have our local repository we already have it
initialized we've already done most of these steps here so we just need to do
these two commands which will configure our project with the correct remote URL
and then push our project to github
so let's go ahead and copy this first
command git remote add origin
head over to our terminal or git bash and make sure
that we're currently in our project location that is the profiles rest api
git project and paste in the command and hit enter
so this configures our project
to add a new remote origin with the path of our remote
git project
next let's copy this command below and head back to the terminal or git
bash paste it in and this should prompt you if you haven't connected to github
before it will prompt you if you want to allow this new fingerprint so just click
yes you should only need to do this the first time you push and now you can see
that it has pushed a new branch, the master branch up to our project so now
we go back to git and we refresh we should see the files that we created on
a local machine appear in our git project so that's how you push a project
to github