Github Basic Terminal Commands

I’m one of those people who’ve struggled understanding Github terminal commands. Now that I finally understand some of it, I’d like to share this here on my blog. This post will cover the basics that you need to know to get started and use GH comfortably 🙂

Installing Git

The instructions to install git and everything around it can be found on the official git website https://git-scm.com/ . Just download the installer and install git on your computer.

Creating a repository on GitHub

This is pretty simple and intuitive. You need to have a GH account. Create on on github.com and then just create a new repository. You can follow their documentation if needed.

Pushing your files to GitHub

Let’s say you create a new repo which says coolest-addon and you have this coolest add-on ready in a folder on your desktop. You can then push it to GitHub by following this guide or by following the instructions below!

  1. Open the terminal and switch to your coolest-addon folder by using the cd command. I’d do something like cd ~/desktop/coolest-addon
  2. Next use git init
  3. Add all files using git add .
  4. They’re now ready to be commited.
  5. Write git commit -m "First commit"
  6. Add URL for remote repo git remote add origin <remoteRepositoryURL> (without the angle brackets)
  7. And finally push using git push -u origin master

Branches

I suggest reading this Stackoverflow thread before you dive in branching. Also checkout this flow for a better understanding about branches. The commands you’d need to remember are:

  1. git checkout to see if your branch is up to date
  2. git branch to see all branches and also to see the active one
  3. git checkout <branch-name> to switch to a branch
  4. git checkout -b <branch-name> to create a new branch and check it out
  5. git push -u origin <branch-name> to push your new branch
  6. git pull to pull changes to your branch

People working on the same project can check your new branch using these two commands:

  1. git fetch
  2. git checkout origin/your_branch

Spoon Knife

I personally learn things by practice, by actually doing them. Starting with Github is tough for most people because we’re scared that we’ll break something or that we’ll make a mistake which’ll be a public embarassment for us. Something that’ll be documented online.

To overcome this fear, you can experiment in a repo called Spoon Knife. The repo is made for beginners to test things out. So feel free to perform experiments there 😀

  1. Specifically, when you visit that repo, fork it to your repositories.
  2. Go through the readme file and make changes in it.
  3. Create branches, pull requests, merge those PRs, delete branches.
  4. Do everything you can till you get it.

That’s all in this post! 🙂