Github revisited

I’m looking at trying to host a node.js instance on something like Heroku and for pushing to Heroku I saw in the Code Train videos on deploying node that Daniel was using git commands to push the info across to Heroku.

Another reason is that I’m sometimes working in the bedroom, sometimes in the living room, and in the past I’ve been using MyCloud to transfer files between the two.

A third reason is that I can fill up their server with my code so I don’t need to save it on my PC. Not an issue with my main laptop but the Surface 3 disk space is struggling.

A fourth reason is versioning and branches. Watching some of the tutorials I see there are several parts to the coding and it changes, so ity would be good to have branches of the code kept at earlier stages that I could go back to if I wanted.

Install & VS Code

I did initially have a couple of issues with this as although I have a github account from before,. I’ve changed the main PC so need to install git on that.

Also I’m now using VS code, for 2 reasons mainly, 1/ It allows you to run a local server and that will update as soon as you save your altered code in VS Code. 2/ It has an inbuilt terminal, so you do not have to have a coding editor open and also a Command Prompt window too, its all in the same programme. That is handy for the git commands as they work in the terminal. A pparently there is a desktop programme but most people use the command line. There are also a few plugings for Git in VS Code. I loaded one but am unsure what it does. Still it works, so thats the main issue.

Code Train playlist for Github

I’ve been looking at these, but jumping around between them. Mainly focussing on vids 6 & 7 in the series

Process 1 Creating repository in Github then cloning on PC

This is video 6 in the series. You create a repository in Giithub then you go to your PC an, in the terminal go > git clone https://github.com/drakemax/JasonServer.git (you give it the url of the github repository.

When making the repository you need to tick the Initialize this repository with a README.

After you’ve cloned the directory, if you have a folder with all your code in, you have to copy/move it across to that new directory- note, I dont think it can be the same name as the original. You also need to go one folder up and create a file with any name in VS Code so that you can open terminal and write the git commands.

Not an elegant method as my workflow is 1/ I write code, then think about sharing it. So creating a repository on PC first seems to work better for me.

Process 2. Git init on your PC then create repository in Github

I started doing this method and got all confused. I banjaxed it and got all confused.

You make the initial >git init in your selected directory

then go across to Github and create the repository, now you can cut/paste the folder name so they are the same name.

Then get the link to the repository and in terminal >git remote origin https://github.com/drakemax/JasonServer.git and give it the URL to the repository.

You do have to make the README.md file on the folder on your PC, but they tell you the code when you make the repository so you just cut/paste the code into the terminal to build it all. See vid below and go to near the end for connection to remote

So, go to the folder where the code is: > .git init

Then > git add .

If you don’t do the add . it sees the repository on your PC as empty of files. Make sure you do it before running the code below, or you have to do the git commit and thn git push again

Then – Copy name of folder to clipboard, go to Github in the browser and make new repository and paste name of folder in there.

Make sure you do not click Init README.md and create.

The code pops up:

echo "# Webscrape" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/drakemax/Webscrape.git
git push -u origin master

cut/paste this into the terminal and run, if it didn’t go, then > git push

Then go to Github and refresh and see if its there.

You may want to add info to README.md file.

And you have a filled Github repository of your initial code.

Updating later, in a folder that is a git repository on your PC:

>git add . (or name specific files that you want to update/add to repository)

> git commit -m “some message to identify an updated version here

>git push

and it’ll push the updated code to the Github repository.

If you are cloning a repository on another computer then:

>git clone {URL pastyed of git repository}

If you are updating a repository on your PC and latest code is in Github then go to directory:

>git pull

Private folders

For free accounts, when I first looked at Github they had to be public. I was always a bit awkward about this as my coding is scruffy and terrible, especially with the brevity of developers.

Now free accounts can have private repositories an as many as you like, apart from the fact that you can collaborate with only 2 (3?)others, otherwise you have to have a paid account. Thats fine as I code on my own.