Getting Started With GitHub

If you have never done anything with GitHub, then you have come to the right place! In other posts on this site and on social media, you have probably seen me mention GitHub and its importance several times. Now I’m actually going to take you through the process of getting started with GitHub.

If you found this post and don’t know much about GitHub, take a few moments and check out my other post on what GitHub is and why you should care. Then come on back and let’s get you started.

The purpose of this post is to help you in getting started with GitHub. I am going to take you through the process and show you everything you need to know to start putting your code on GitHub.

I’m going to cover:

  1. Creating your GitHub account
  2. Installing Git
  3. Creating a repository
  4. Cloning a repository
  5. Making Changes
  6. Pushing Changes
  7. Pulling Changes

Seems like an awful lot with a bunch of technical jargon mixed in. But I promise that by the end of this tutorial, you will feel very comfortable with GitHub and I will share with you my absolute favorite GitHub learning resource.

Let’s get started!

Getting Started With GitHub

When you are first getting started with GitHub, there are a couple of things you need to have.

  • A GitHub account
  • Git installed on your computer

Let’s start with the easiest first.

Create a GitHub Account

First things first, let’s create a GitHub account. It’s actually quite simple. All you need to do is go to GitHub and you will see something like this:

getting started with github

There are two ways to get started and they both wind up leading to the same place. You can fill in the form on the home page with a username, email, and password and click the big green “Sign up for GitHub” button. Or you can click the little white “Sign Up” link at the top right corner of the page.

If you fill in all the information without an issues, you should reach a page that looks similar to this one:

getting started with github

This means that the username, email address, and password you have chosen are all valid.

Congratulations!

Click the green “Create an account” button.

At this point you will be presented with some options about choosing a plan:

getting started with github

Go ahead and stick with the “Free” plan. It will be more than enough for you to get started now and grow with you for quite some time to come.

I typically leave the 2 check boxes at the bottom unchecked and click the green “Continue” button.

At this point, you have actually created your account and can get started. You are given some more tailoring options that look like this:

getting started with github

Feel free to fill as much or as little of this out as you want. If you want to fill some out go ahead and do it and then click the green “Submit” button. Otherwise go ahead and click the little blue “skip this step” link right next to the “Submit” button.

Congratulations!

You now have your very own GitHub account. But don’t get too excited. We aren’t done yet.

Installing Git

OK, I haven’t really mentioned much about this yet. So now is the time to bring you up to speed a little bit more.

Yes, you can get away with only having a GitHub account and a browser, but most professional developers don’t do a lot of interacting with the GitHub website for code management on a day to day basis. We use it for other things like Pull Requests, which we are going to save for another day.

To handle most of the interaction we use a software called Git.

What is Git?

Git is what is know as a distributed version control system, or VCS. If you read my previous post on what GitHub is, then you will know that I listed several benefits of GitHub including saving your code, tracking changes, etc. Well it’s time for me to be honest.

I lied.

It really isn’t necessarily GitHub that does all those things. Git plays a big role. GitHub is a web based interface and management system that allows for you to create repositories that run on Git in the cloud.

So the best way to interact with GitHub is using the tooling that it natively uses. And that is…Git.

So let’s install it.

Installation

If you are running on a macOS or Linux based computer, odds are fairly decent that you already have a Git client installed. To test whether or not you do, use the following command in your terminal application:

git --version

If you already have a git client installed you will get a response similar to this one:

getting started with github

Your version may look different based on your operating system and version of Git.

If you don’t get a positive response you will need to install a client. To do that, simply go to Git Downloads page, and select your appropriate operating system to download the installer.

Once again, the installation for each operating system will vary, but will typically require you to click a few buttons, leave the default options checked, and finish the installation.

Once the installation is complete, try the Git version command above again and you should see the version of git you have installed.

If not, once again, close your command prompt or terminal windows, reopen them and try again. That should do the trick.

Create a Repository

With the proper accounts and tools setup, you are now ready to create your first repository. This is actually much easier than it sounds, but we will take it one step at a time.

Open your web browser and log back into GitHub if you aren’t already. After doing so, you should be presented with a screen that looks something like this:

getting started with github

All you need to do now is click on the green “New repository” button towards the bottom left of your screen.

You will be taken to the Create Repository screen that looks like this:

getting started with github

I know it seems like there is a lot going on here, but let’s break this down and take it one step at a time.

Repository Name

Every repository you create in GitHub needs to have a name. You are going to want to give this a name that means something to you so that you can remember what is in it.

Start by typing the name in the Repository name box at the top of the screen.

Description

The description field for your GitHub repository is optional, but I would highly recommend filling this out. Give your repository a meaningful description so that, once again, when you are looking through you list of repositories later, you will remember what you are using this one for.

It doesn’t have to be a long, detailed description. Just a sentence or two should do just fine.

Public or Private

By default, all of your repositories are going to be created as Public. And, unless you created a paid GitHub account, you will only be able to create public repositories.

All public means is that anyone that has a GitHub account can find this repository if that wanted to. It also means that you can easily share this repository with someone else by simply giving them the URL to it.

Initialize Repository With a README

A readme file in GitHub is where you will eventually put a much more detailed description about what this repository is, what type of code you wrote, what the application does, etc, etc. You could really put anything in here that you want.

I would recommend checking this box so that GitHub will create this file automatically for you.

GitIgnore

The first dropdown box you see at the bottom has to do with automatically adding a .gitignore file to this repository. A .gitignore file is a special file that Git knows how to use in order to keep the amount and type of files getting saved into this repository to the absolute minimum. Without a .gitignore file, Git will try to save absolutely every file, whether it is needed or not, and that’s often unnecessary.

When you click this button you will be presented with a list of options for what type of .gitignore file you want to add to this repository. This will always depend on the type of language and the type of application you are creating.

To keep things simple at this point, click the button and select “Visual Studio”.

License

The final input that GitHub needs to create your repository is the type of license to add. In this case, for the most part, the license has to do with what other people can and can’t do with the code they find in this repository. This may become more important later on when you are creating lots of code that could be useful to other people, but for not you really don’t need to worry about it too much.

Just leave it alone for now.

For more information on the available licenses and what they are for, check out choosealicense.com.

Once you have filled in your inputs appropriately, it should look something like this:

getting started with github

As you can see, when you fill in the repository name field you can include spaces. GitHub will also inform you of what the actual repository will be named.

Now just click the green “Create repository” button and you are on your way!

After clicking on the green button, GitHub will create your repository and redirect to it’s page:

getting started with github

There it is! Congratulations!

You’ve created your first GitHub repository. There’s lots of stuff going on here, but don’t worry about most of it. It will all come in time.

Just take a look around and you will see some things that look familiar. You should see things like the repository name, the description you typed in, as well as a .gitignore and README.md file.

We’ll get deeper into the details of your repository another time. For now, it’s time to move on.

Basic Workflow

Now that you have your repository created, you should be quite happy. But there’s a problem. It’s not doing you much good up on the internet. To really take advantage of it, you need it on your computer.

Now we are going to cover the basics of the common workflow you will use when interacting with your GitHub repository.

Clone

The first thing you are going to want to do is get this repository copied to your computer so you can use it, modify it, save it, etc. The process of copying a remote repository (that’s a repository that isn’t currently on your computer) to your computer is called cloning.

This is where we start to use our Git client.

First, you are going to need to get the URL for your repository.

If you look again at the main repository screen, you will see a green button that says “Clone or Download”:

getting started with github

Click that button and you should see another box pop up:

getting started with github

Inside this box you will see a URL that starts with “https://github.com/”. Copy that entire URL. you can also just click the little clipboard icon to the right.

Once you have that, you will need to open your command prompt or terminal application and type the following command:

git clone "<your_repository_url>"

The “<your_repository_url>” part needs to get replaced with what you copied from your repository. For example, mine looks like this:

git clone https://github.com/startwritingcode/Getting-Started-With-GitHub.git

Hit the enter key on your keyboard and away you go. Depending on your setup, Git may or may not ask you for your username and password. If it does, type them in and hit enter.

After Git has a chance to do its thing, you should see something like this:

getting started with github

As you can see, the second line in my example says it’s “Cloning into ‘Getting-Started-With-GitHub’”. This means git created a new folder for me and put everything from my repository into this folder.

How nice!

Make Changes

The next thing that will usually happen is that you will make some changes. You will modify files, add files, delete files, etc. Whatever sort of changes you want to make. Make them.

Let’s do a little sample now.

Start by opening the contents of your new directly in Visual Studio Code.

Don’t have Visual Studio Code? Check out my post on getting started with C# Development.

Use the following two commands:

cd <your_folder_name>
code .

Make sure to replace “<your_folder_name>” with the actual folder name the git created for you. My commands look like this:

cd Getting-Started-With-GitHub
code .

Make sure to include the period at the end of the second command. This tells Visual Studio Code that you want to open the current folder.

After successfully executing these commands one at a time, Visual Studio Code will open and it should look very similar to this:

getting started with github

Once again, there’s a lot of stuff going on here that we aren’t going to worry about now. You can refer to my getting started with C# development post for a brief primer on Visual Studio Code.

All you should basically see are two files in the left pane:

  • .gitignore
  • README.md

Take a look at them if you wish by clicking on them.

Create a File

You can make any changes that you want, but I find the easiest way to get started is to create a new file.

Right-click somewhere in the left pane below the README.md file and select “New File”. Visual Studio Code will give you a space to type the name of the file. Let’s just name it “index.html”.

Inside of this file, simply copy and paste the following:

<!DOCTYPE html>
<html>
   <head>
      <title>Document</title>
   </head>
   <body>
      <h1>This is my first GitHub change!</h1>
   </body>
</html>

Stage Your Changes

Before you can send your changes back up to GitHub, you need to let Git know which files you want to send up. This process is knowing as “staging” your changes. There are several ways to do this, but we are going to stick with the simplest one.

At the command prompt, make sure you are still in the directory that Git created for you, and type the following command:

git add -A

This command is going to go through all the changes, additions, and deletions to files you have made and stage them inside of your local repository in git.

If everything goes correctly, you won’t see any response in your command line.

Commit Your Changes

Staging your changes is like putting them into a holding area to get them ready to be shipped off. But before they can be shipped off, they need to be committed to you local repository. This process will update your local copy of the repository with all the changes you have made.

When you commit your changes, you will need to provide a commit message along with them. This allows you to describe what changes were made in this group of changes, known as a change set.

To commit the changes, execute the following command:

git commit -m “My first changes”

getting started with github

You can see now that git has recognized that you have changed 1 file.

Now it’s time to send these changes on their way.

Push Your Changes

Now that your changes are committed to local repository, it’s time to send these changes up to GitHub for safe keeping. The process of sending your local changes to GitHub is knowing as “pushing”.

Once again, there are many ways to push these changes to GitHub, but we are going to keep things as simple as possible with the following command:

git push origin master

Origin? Master? What the?

Origin and Master are really just terms used to describe your local version of the repository (origin) and the remote GitHub version (master). That’s all you really need to know for now.

At this point, you may be prompted for your username and password. This is git verifying that you have access to this repository on GitHub and that you are allowed to make changes.

If prompted, simply enter your username and password and hit Enter.

You should then get a positive response:

getting started with github

If you go back to your repository on GitHub and refresh the page, you should see your changes:

getting started with github

Pulling Changes

To this point, you have learned to clone a repository, makes code changes, and get those changes pushed back up to GitHub. This is great, but what if there are other changes made in GitHub that you need to get to your local version of the repository?

That’s where pulling comes in.

In order to pull remote changes into your local copy, you use the pull command like this:

git pull

If there are changes in GitHub that you don’t have locally, this will show you what was pulled down. In our case, that is unlikely, so you will probably see a message like “Already up to date”, or something similar.

Summary

Congratulations!

You have made it through the entire Getting Started With GitHub process. It was a long road, but one that you will be very glad that you made.

There is much more to learn about GitHub and Git, but this will get you pretty far at the beginning of your journey.

Before you go, let’s have a quick review of the process and terminology.

Review

You began by creating a new repository in GitHub through your web browser. You then made a copy of that repository on your computer by a process known as cloning. Cloning is accomplished with git clone.

You then made some changes to the files. These changes could include creating, modifying, or deleting files.

You then wanted to get your local changes up to GitHub. This process took 3 steps:

  • Staging your changes: git add -A
  • Committing your changes: git commit -m <message>
  • Pushing your change to GitHub: git push origin master

From there, if you ever want to pull any additional changes from GitHub down to your local copy, this can be accomplished by pulling with git pull

Where to Go From Here

Earlier in this post, I mentioned sharing with you my absolute favorite Git learning resources. And it’s time to spill the beans. Both of these resources are free and provide great documentation and hands on learning. Which, in my opinion, is the only way to learn.

Check them out!

GitHub learning resources
Git Tutorial on Codecademy

Happy Coding!

One thought on “Getting Started With GitHub

Leave a Reply

Your email address will not be published. Required fields are marked *