Coding Tutor Tip — 5 — GitHub Essentials
There must be some ten thousand GitHub ‘how to’ articles out there. Which makes perfect sense, and that is why, I will add one more ‘how to’ because why not.
Anyway, GitHub of course, is the primary way to manage code. As always, I will mention here that I have been freelancing full time since 2012. Interestingly enough, as a self taught developer (now retired) and tutor (still actively pursuing this line of work), I did not start using version control, repositories and tech like Git, GitHub and BitBucket until 2016.
Yeah, I used to zip files up, and put them on OneDrive. That was my version control. Oh my god! I laugh thinking about this. This is the problem with being self-taught. You miss the obvious things that even a high schooler would know.
This a sequel to my previous post, Coding Tutor Tip-4-Suit Up With Essential Computer Gear.
Anyway, my experience with proper git usage was bitbucket. Of course, GitHub was already the more popular option. Unfortunately, in 2016, GitHub did not allow private repositories for free accounts. Bitbucket did. Then, a few years later, GitHub also started offering private repositories for free accounts, and I migrated over to GitHub.
God, I miss bit bucket, but it’s just not as cool as GitHub.
Now, for my students, past, present and future, here is my tips and workflow, when working with GitHub. The advice is a mix of commands, general tips and knowhow.
Item 1 — Install Git (on Windows only)
This one is straight forward but not neccessary. The thing about universal things like Git tech, is that, there are always multiple ways to skin the cat. I personal like to use Git, especially for the initial setup and cloning of a new repository.
Find the git to install here — https://git-scm.com
On Mac, dont install anything. The built-in terminal on Mac is all powerful and amazing.
Item 2 — Install Visual Studio Code
This one is another no brainer. Although, I usually use Git command line for cloning a fresh repository, post cloning, I stick to using the built in terminal in visual studio for running all git commands.
Also, there are several git extensions which help with Git Flow like authentication, GitHub Actions and so on. Very useful.
So, for cloning, use Git SCM. After that, use the VS Code terminal for all post cloning git activities.
Item 3a — First Time Repository and Cloning
note: I realized that I never wrote how to get started with a new repository. so, updating this on November 6th, 2022.
First, you want to create a ‘private’ repository in your new GitHub account. It’s very important that you do the ‘private’ repo.
Then, get the clone URL from the ‘green’ button. it will look something like this.
https://github.com/Jay-study-nildana/bootstrapexpert.git
Right then. you want to clone it on your computer, either using gitbash or VS Code terminal.
git clone https://github.com/Jay-study-nildana/bootstrapexpert.git
after cloning is successful, remember to open the folder inside the repository (not outside) from your VS Code. Otherwise, you will keep trying to use git in a folder that contains the repository folder, not the actual repository.
Item 3 b— Essential commands
- ‘git status’ — I do this frequently and all the time. Allows you to check and avoid git conflicts
- ‘git add .’ — Adds everything in the current working folder.
- ‘git commit’ — commits what you have added in step 2.
- ‘a’ — for beginning to type comments in the git commit window. You know, you should at least type two paragraphs. The first paragraph (which should be a simple line, preferably short, like 2 to 6 words) is like the title of a paragraph. The second paragraph (or multiple paragraphs if you want to get into story writing mode), is where you put all the details of the current commit. Further, I usually use a simple ‘interim commit’ as both title and paragraph when I am doing a quick, safety commit.
- ‘Shift : wq’ — exit out of the commit message
- ‘git push’ — pushes all the changes along with the commit message.
Item 4 — Branch management
Yes, yes, people will say that you should learn every git command on earth and you should do everything in the terminal. However, I dont believe that.
The goal here is code management.
So, I personally prefer using a combination of VS code branch UI (bottom left corner) and GitHub website for all branch related activities. Yes, you can do this stuff from the command line, but I dont mind taking the easy route. Especially if it saves time and makes my students life easy.
Item 5 — Other Things
For some bizarre reason, people seem to keep forgetting their GitHub passwords. Please, please, write down your password somewhere.
Also, remember that by default, new repositories (at least in my experience) are public. Ensure that it is set to private.
Enable 2 factor authentication. You may be working on a simple project, but, always good to get the basics of securing your code from your young, early days of development.
Remember that, when you delete a repository, you lose those nice ‘green dots’ of committing on your github profile. If you no longer like a repository, instead of deleting, consider archiving it.
Learn basic markup. Put a readme.md file in each and every project folder. Don’t create folders without readme.md. It just makes the whole thing ugly, and makes you look like a lazy developer. Both the web editor on GitHub, and the VS Code, have very good, preview options for what you are typing. Make the most of them, and get better at marking up.
GitHub is almost like a social media these days. Follow interesting people (hey, you can follow me here — https://github.com/Jay-study-nildana). Also, begin ‘star’-ing projects that you like. Every day, I learn about new, useful and money making repositories due to GitHub recommendations.
Never feel like you are too small to raise a pull request on big projects. I am, at best, a below average coder and developer. Yet, even with my limited programming skills, some of my pull requests have been accepted on big open source projects like Microsoft repositories. No contribution is too small, and it always makes you feel better. Like when some Microsoft Program Manager from US replies to your pull request and says thanks. Thats a cool feeling.
Final Note
Well, the above contains things that I normally tell to my students. Now, it’s here in written form. Hope it helps.
A sequel to this post, is now available here — Coding Tutor Tip-6-Is Coding For You?
I work as a full time freelance coding tutor. Hire me at UpWork or Fiverr. My personal website is here