blur code

Blur Code

Working towards providing new and cool programming articles.
A perfect blend of knowledge & technology to become a better coder

Everything you need to know about git | Git 101

How to use Git version control. Everything you need to know before using git.

Prakhar Kaushik

4 minute read

If you have never worked with github before, then it can be a bit confusing to start with, all those terminal commands. Push Pull Merge etc. But honestly, its quiet simpe once you understand what everything is.

Okay so lets answer the question

What is git?.

In simple words , Git is a type of version control system or (VCS). Its sole purpose is to track changes to your project. It is very helpful when more than 1 person is working on the source code.


Difference between Git and Github.

The key difference is that unlike Git which a programmer installs locally , Github is an online platform where you can share project with rest of the world, work with people together on a single project or contribute in someone’s project.

Basically a social media platform for coders :)


1. Start With Your First Project On Github.

Note: A repository is basically a structure where you will upload your project source code.

Source Github
Source Github
- Provide a name for your repository After this you will see a page like this
Source Github
Source Github

With this we are done with step one!!

Copy the link you see https://github.com/username/repo.git on your repo page.


2. Install Git locally

Now its time to spin up your terminal and start with git locally, if using windows then powershell can be used.

  • First check whether you have git installed or not use git --version -> git version 2.25.1
  • If you get the above output then you can move to next step otherwise use sudo apt-get install git for debian and ubuntu users or look on official guide to find git for your linux distro/windows.
  • Once you are done with git installation, create a new folder, start an empty git repo using git init. You will see something like this on your terminal
Source My Linux
Source My Linux

3. Push file to Github

Till now we have our Github repository and a local repository created by git on last step. Now its time to first connect both of them and then push a file to it.

Connect local git repo to github repo

Remember I told you to copy the link of your github repo, its time to use it. - To connect the local repo to github use command git remote add origin <url>.

After this you can check it by using git remote -v Your terminal will look something like this

Source My Linux
Source My Linux

Lets understand this command!! So here we created an alias origin for our github repo, the benefit of this is if you are working with multiple online version control platform. You can connect to all of them using single project just by creating differnt remotes.

Eg: git remote add heroku <url> This will create two remotes, one origin another heroku.

Once we are done with creating remotes, next step is to push something to github.

Create File

  • Create a file touch README.md
  • Put something inside it echo "#First Commit" > README.md
  • Cat README.md
Source My Linux
Source My Linux

Push to Github

After we are done creating file, lets push it to Github. - git add . - git commit -m "Message for commit eg: First commit" - git push origin master

It will ask for your github credentials, with this your terminal will look something like this.

Source My Linux
Source My Linux

Done!! Check your Github Repository , you will see the file there, uploaded with your commit message.

Source My Linux
Source My Linux

Congrats!! You have successfully pushed your first file to github.

In next article we will dive a bit deeper into git , will talk about Merge requests, Branches, Rebasing etc. So stay Tuned.


Reviews

If You find it interesting!! we would really like to hear from you.

Ping us at Instagram/@the.blur.code

If you want articles on Any topics dm us on insta.

Thanks for reading!! Happy Coding

Recent posts

Categories