DEV Community

Cover image for Git and Github, An Intro for Beginners
Akhand Patel
Akhand Patel

Posted on • Edited on

Git and Github, An Intro for Beginners

Most of the developers use GitHub or any other Git Client in their development cycle. But have you always wondered what is git and why do they use it?
In this post, let’s look at the basics of git and how easy is it to create your first repo on GitHub.

What is Git?

Git is an open-source project developed in 2005 by Linus Torvalds (Yes, you guessed it right, the famous creator of Linux Operating System). It is a Distributed Version Control System.
That sounded like a charm straight out of J. K. Rowling’s Book. Let me explain it in muggles’ English.

Version Control System (VCS)

VCS is a tool that allows users to track changes in the content. It keeps track of various changes made to the content as people and multiple teams collaborate.
In layman terms, Think of the content as a book you and your friend are writing together, you both come with different ideas for the arc of your character and make various versions of the story over time as characters increase so does multiple storylines, it would be a nightmare to keep everything in order, this is where VCS comes into play, it keeps track of following things
-What changes were made?
-Who made the changes?
-When were the changes made?

If you want to go back to the storyline where your protagonist doesn’t die, you can just revert to it. You can Merge your friend’s ideas into your version. If someone screws up, he can just compare with the previous versions and rectify the mistake without disturbing the others.

Repository - It is like a folder for your project’s files. It contains all of your project files and their detailed history.

Distributed Version Control System (DVCS)

DVCS means that the code isn’t just hosted on a single server or system but also distributed across various systems. This means that each developer has a copy of the code on his local system.
Git has a remote repository stored on a server and a local repository stored on the developer’s computer. Developers don’t need a constant central connection to the remote repository and can collaborate suiting their timetable. Each developer has a transparent history of changes, who made the changes and when.
So now we have the basic introduction of Git, let’s look at GitHub.


What is GitHub?

I read the following line somewhere on the internet and to me; it is one of the best definitions for GitHub.

What Pornhub is to Porn, GitHub is to Git

Jokes apart think of it in this way, when you use git locally you can only manage your local code but that is rarely the case, mostly you have to collaborate with other people or teams and for that, you need to have a remote repository setup on the cloud, here GitHub fits in.

GitHub is a git hosting repository service, but it adds many of its features to the core git. Git is a command-line tool but GitHub is an interactive website that also allows some unique features on top of Git like GitHub Flow (Sounds like an excellent idea for the next post). There is a community of over 15 million developers on GitHub.

How to Create your First Repo

 Are you excited to create your first repository from scratch?
But first, install git on your system from here and create a GitHub account if you haven’t.

Let’s Begin Now!!

Important: The following instructions are for bash terminal

-Create a directory for your project using the mkdir command

mkdir firstProject 
Enter fullscreen mode Exit fullscreen mode

-Go into the new directory

cd ./firstProject/ 
Enter fullscreen mode Exit fullscreen mode

-Initialize the Git repo using git init

git init 
Enter fullscreen mode Exit fullscreen mode

-Create a file now

echo “This is my first line of text in file” > readme.md 
Enter fullscreen mode Exit fullscreen mode

-Add the files to git. After this command, the Git will keep track of the changes made to the file.

git add readme.md 
Enter fullscreen mode Exit fullscreen mode
  • Commit (save) the changes to git, the command tells to save the changes along with the message “initial commit”
git commit -m “initial commit” 
Enter fullscreen mode Exit fullscreen mode

You now have a local git repository. You can use it locally, but I would rather host it on my GitHub.

Connecting it to GitHub

-Go to GitHub,
-Sign in to your account
-Click on the new repository button (Hint: It has a green background)
-Enter the repo’s name “firstProject
-Click Create Repository
You would see sets of instructions on the page, follow the second one -or push an existing repository...

git remote add origin https://github.com/yourUsername/firstProject.git 
git push -u origin master 
Enter fullscreen mode Exit fullscreen mode

The first command adds the remote address of the repository to the Git and the second command tells the system to push (send) local repo to the remote origin repo.

Voila!! You have successfully hosted your first repo on GitHub.Give yourself a treat today, you deserve it.

This is my first post on any platform, so kindly share your reviews and suggestions in the comments. I would very much like to improve. I guess we all learned something today.

Top comments (0)