How to get started with Git and GitHub? Let’s find out!

In this article, you will learn how to make a git repo, add it to GitHub, and commit code to it. Let’s get started!

Harsh Prateek
5 min readApr 20, 2022
Photo by Roman Synkevych 🇺🇦 on Unsplash

Global Information Tracker or Git is commonly known as a version control software that lets you keep track of all the changes which are made to the codebase. It stores the changes made to the code and lets you compare the current state of the codebase with something it was in the past. It is helpful in times when you have introduced a bug while implementing a new feature to the codebase, with the help of git, you can revert the code as it was before the introduction of the bug and start all over.

Git can save your code locally and you can share it with a few developers around you physically, to share the code around the world we have GitHub. It is like the Facebook or Instagram of the developer community. Here, everyone shares what they are making and they also share the code along with git version control. GitHub is like a git repository for all your code but it is online.

Let’s see how to get started with GitHub first then we will see how to use Git.

GitHub:

Signup and Login:

First of all, to get started with GitHub You have to make an account on it. When you go to GitHub for the first time you will see this screen

Image of the landing page of GitHub
The landing page of GitHub

Here, you can signup using your email or you may use google, Facebook, or Microsoft authentication. You also have to make a username that would be used in the future to authenticate your repos. After you have done signing up successfully this page will appear:-

Landing page of GitHub
Image of the landing page of GitHub

Creating a new Repository(repo):

Now, click on the plus icon on the navbar and make a new repository. Once you click New Repository in the dropdown menu of the plus icon, this page will appear:-

image of New Repository page of GitHub
This is the page where to make a new repository

Now, give the repo a name, set it public or private as per requirement and click on the Create repository button. Now you will get a URL of this repo which needs to be pasted on the terminal where you will use git commands. Here is the page which will appear after this:-

Page which gives the URL of the repo
This page will provide the URL to be connected with the local repo

Here, on this page, you will get the link of the repo which you will use to connect the GitHub repo to the repo we are going to make locally in the terminal. Here we are done with GitHub and will now proceed to learn how to use git commands on command line terminals like Linux or windows PowerShell to make a local git repo.

Git:

Installing the Git to the system

First of all to use git you have to install it for your OS from here. Download and install. Git in your system then open the terminal app which is present on your device. Paste the command given below to check if git is installed correctly or not.

git

If Git is correctly installed in your system then you should get these messages on the terminal:

Commands which will appear once git is installed
These commands will appear if git is installed

Making a Git repo locally

After this, make a new folder and open it in the terminal, then paste this command into the terminal:-

git init

This command makes this folder a git repo and now you can make files in this folder and add them to the Git program for version control. For starters, make a README.md file in this folder and then type this command to add it for version control. Here is the command:-

git add README.md

This will make the README.md file a git file. You can also tell git to not include certain files if you want. Open the .gitignore file in your folder which was created by GIT and write the names of the files which you don’t want to add to git then paste this command:-

git add .gitignore

We have a git repo locally, let's see how we can commit to it.

Making a commit to the repo:

Making a commit means that you are saving the code up to that point in time. To make a commit to our local repo paste this command in the terminal.

git commit -m "This is the message which will be saved with commit"

In the above command git commit -m is the actual command which makes a commit and the message in the quotes is the message which you can give to remember what this commit store. At this point, the repo has saved its state for further use by this commit. No matter what changes you make but the code you committed will always be the same, it is unchangeable until the repo is deleted. Now, we will see how to connect this local repo with our repo on GitHub.

Connecting Git to GitHub:

Now, we will connect the local repo with the repo on GitHub. To do this paste the command given below to the terminal window:-

git remote add origin https://github.com/<your_username>/<Your repo name>.git

This will connect the GitHub and local repo with the same name and store the files in the master branch of the repo. The origin is like a variable we are giving the value of the link to our repo on GitHub. This way, we would never have to use the full URL and we can simply use the origin keyword to commit, push or pull from GitHub. Now to push(upload) the changes in the folder to GitHub, paste the following command:

git push origin master

Master is the branch where we are committing, you are free to change the names of origin or master but be consistent if you do as these will be the identity of your project on GitHub.

Congratulations:

We have done it guys, we have made our first git repo and committed it to GitHub. Feel proud of yourself as you have done something which makes you a true dev now. Good luck with the rest of your journey as a dev. Also do let me know in the comments what you think about the article and follow me as I post these kinds of articles on Web development and coding daily.

Have a Great Day

--

--

Harsh Prateek
Harsh Prateek

Written by Harsh Prateek

Hi, I am Harsh and I write about coding and learning techniques. I am a student myself and would love to tell everyone my secrets for coding and learning.

No responses yet