GIT is a control system that is going to help us keep track of a few things for our deployment. It will help us track our edits, track what files we need indcluded in our deployment, and where we are going to be deploying out site to. the basic GIT commands that we are going to work with are
git add -A,
git push heroku master. The first command
git status will tell us what we have changed and if there are files that we have added to our file tree that are untracked (meaning will not be pushed to our live stie if not added). The second command,
git add -Ais used to add any untracked files to your repository. The third command
git commit is actually packaging everything we want to push to our hosting for our live site. It is usually seen like this in the real world
git commit -a -m "message to go with commit". the
-a -m is saying include all that is being tracked and add this message as a reference. The last one
git push heroku master is what we will use to send your information to Heroku to be posted live on your site. Lets do our last stages of setup before we install GIT and get ready to push to our hosting.
Mongo Connection String
To get your connection string you need to be in your Mongo Atlas account and looking your cluster. Seletc the connect button that is directly under you cluster name and then choose the option connect your application. Copy that connection string and add your database admin password (not your login password) in the string and put it on a blank text file. You will need this string immediately after we set up our heroku hosting.
Before we start using GIT we need to do a few small setup steps to get Heroku ready. In your command line you need to run
npm install heroku -g, this will install Heroku's CLI and allow us to sync our account from our C9 terminal. Once that is done, type in
heroku login -i in your command line and login with your username and password. Lastly, type
heroku create and you will see that it creates a new app for you. Once that is created, go back to Heroku. Click on Settings and then click Reveal Config Vars. The key is the variable name we gave in our code on C9 and the value is your personal setting that is needed (example: process.env.MONGO for your mongoose string separates to KEY: MONGO and value: your string). Once you have added all the variables, close the cofig variable windows and lets get back to C9.
To start using GIT we are going to hit the command line with
git init and you should see a line generate in your command line similiar to Initialized empty Git repository in /home/ec2-user/environment/v3/.git/. Type in
git status and you should get a list of the entire diretory that are untracked files. Type in
git add -A to add the entire directory to your repository. It will take a second but you will see your entire directory plus the Heroku CLI get added to your git. type in
git commit -a -m "initial build load" so you have git ready to load up.
We need to run
heroku apps in the command line to get the exact name of the app that you are going to use. Once it generates that line, you need to type in
heroku git:remote -a yourAppNameFromAbove to direct your GIT push to your heroku app. You should see a line that says set git remote heroku to https://git.heroku.com/yourAppHere.git to know that it took successfully. Ok, now that we have the setup down, lets transition and get ready to deploy the first time.