How to create a Github Repository and Initialize Git

·

3 min read

"Git" and "Github" are commonly used in the software development industry and can be a bit confusing for a newbie. Firstly, Git and Github are not the same things. Let's see Git as a tracker, it tracks the changes in our codes or different versions of our project. Github is like a cloud showroom. This is where developers share their git projects and collaborate with each other on a project. These projects are stored in a Github Repository.

Let's start with creating a Github Repository.

  1. Go to Github.com
  2. Create an account or log in if you have an existing account.
  3. On the top right corner, click on the drop-down beside a + sign. image.png
  4. Click on 'New repository" and you should see this image.png
  5. Fill in your Repository name and Description which is optional but advisable to do so.
  6. For now, leave the README file unchecked and click on "Create repository" image.png
  7. You should have something like this image.png

Git Initialization. Now our Github repository is created, it's time to initialize git in our project.

  1. On your terminal, cd into your project directory. For the purpose of this tutorial, we'll use a "test" folder on the Desktop that contains an HTML file. "C:\Users\Ibejih\Desktop\test\index.html"
  2. Run git init -b main image.png
  3. git add . notice the period(.), it means you are about to add all the files in that directory image.png
  4. git commit -m "(This should be a short but meaning description of what you are committing)". This is our first commit so we can use "Initial commit" or "First commit".
    git commit -m "Initial commit"
    
    image.png
  5. After committing, the next stage is to push those commits to our Github Repository. For that to happen, we need to point our local Git on the right path. It needs to communicate with our Github Repository and know it's the right Repository we want to push our committed file(s) to.
  6. git remote add origin <Remote URL> where 'Remote URL" is the URL to our Github Repository image.png

image.png To make sure it worked, run the command git remote -v image.png

  1. If you've made it to this point and everything is working fine then, it's time to push our file(s) to our Github Repository else go through the steps again. You've got this!
  2. To push, run git push origin main image.png Go to your Github Repository and refresh the page image.png

You can now add a README file. Congratulations on learning how to create a Repository and pushing your code to Github by using Git commands.