Before we start, I want to state that this tutorial is for absolute beginners who want to learn git and GitHub.
The tutorial has no specific prerequisites
After reading this tutorial youβll be able to answer the following questions:
- What is git?
- How does git work?
- What is GitHub?
- Why do we use them?
- What is the difference between git and GitHub?
Introduction
In laymanβs terms, git is used to save different versions of your project.
Now the question arises,
Why backing up different versions of your project is important? π€
To understand this, letβs move to an alternative universe with no version control system.
In that world you are working for your dream company. Your team has been asked to work on an important project and your job is to build the back-end.
You write the code. π»
You run it for the first time. π
It works Perfectly.(In the first try..Ohhhhhhh) π³
It is working as you intended. π
Itβs the best code that you have ever written in your life. π
You pass it to your team members and..........
somehow.....
they frick that up. π±
Fine! π
It comes back to you and you have to fix it because you did not have any backup.
Now you fix it. But itβs not that perfect as it used to be. π
Then your teammates do their part. Your team leader shows it to the project manager. The project manager shows it to the client.
They like it. π
BUT this is their reaction.
So now they ask you to DOUBLE the features. They are paying you for that. Itβs your job. You have to do it.
So, you work on the logic. AGAIN ππ»
You add the features asked. π»
It is passed on to your team members and they do their part.
Your team leader shows it to the project manager.
Your project manager shows it to the client.
And this is their reply.
βI think we like the previous oneβ
Now you cannot go and be like:
(You have to be polite and do as he says because heβs not a little crap. Heβs a big crap and he can do a lot of crappy things to you and your career.)
I think you get the point that why we should back up different versions of our project.
What is git?π€
Git is a Distributed Version Control System created by Linus Torvalds in 2005 for the development of the Linux Kernel.
(Note the terms "Distributed" and "Version Control Systems")
What is a Version Control System?
Version control systems are a category of software tools that help a software team manage changes to source code over time.
Version control software keeps track of every modification to the code in a special kind of database.
(In Laymanβs term: It is like that save game mechanic for your software development)
Before Distributed Version Control System, Centralised Version Control System was popular.
Let's have a look at Centralised Version Control System.
- In centralised version control system we have a server and a client.
- The server is the main repository which contains all the versions of the source code.
- Client fetches the code to local machine, works on it then commits it to the server.
(If you didnβt understand words like commits and repository. Hold your horses. Weβll look at them later)
Laymanβs Language
In centralised version control system, we have a single server that contains all the versioned files and the clients check out files from a central place.
So basically, to work on any project, firstly the user or client need to get the code from the server or main repository.
Once you get the latest version of code, you start making your own changes in the code and after that you simply needs to commit those changes straight forward into the main repository.
(Here committing your changes means to merging your code to the main repository or making a new version of the source code.)
Linus Torvalds didn't like Centralised Version Control System, so he created Git
What is a Distributed Version Control System?
Being distributed means that you do not have one central location that keeps track of your data.
No single place is more important than any other single place.
In distributed version control system, the client doesnβt just checkout the latest snapshots; rather they fully mirror the repository, including its full history
How does git work?π€
Let us first look into some of the important terminologies:
-
Snapshots
- It is the way in which git keeps track of your code history
- A snapshot is essentially a recording of what your file looks like at a given point in time
- You decide what you want to include in a snapshot and what you want to exclude
- You have the ability to go back to any snapshot
-
Commit
- The act of creating a snapshot.
- You project is essentially bunch of commits.
-
Repository
- Often called "Repo"
- A collection of all the files and the history of those files
Workings of git
With Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
If files have not changed, Git doesnβt store that file again, just a link to the previous identical file it has already stored.
The mechanism that Git uses for this check summing is called a SHA-1 hash.
A SHA-1 hash is a 40-character string composed of hexadecimal characters (0-9 and a-f) and calculated based on the contents based on the contents of a file or directory structure in Git.
A SHA-1 hash looks something like this :
24b9da6552252987aa493b52f8696cd6d3b00373
Git Workflowπ§
The basic Git workflow goes something like this:
You modify files in your working tree.
You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the staging area.
You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.
Git has three main states that your files can reside in: modified, staged, and committed:
Modified mean that you have changed the file but have not committed it to your database yet.
Staged means that you have marked a modified file in its current version to go into your next commit snapshot.
Committed means that the data is safely stored in your local database.
To Understand this better, try and imagine shopping at a store πͺ
You pick the items.
You add them to the shopping cart.
You go to the counter and create the bill.
The bill is your commit.
The shopping cart is your staging area.
There are various items in the store, but the only things added to your bill are the items you put in the shopping cart.
What is GitHub?π€
GitHub is a United States-based global company that provides hosting for software development and version control using Git.
It offers the distributed version control and source code management (SCM) functionality of Git, plus its own features.
It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project.
It is the largest host of source code in the world.
What is the difference between Git and GitHub?π€
- Git is a version control system while GitHub hosts your git repositories(ie. puts them on your GitHub account and makes them accessible from anywhere in the internet)
- Git is a command line tool while GitHub is a website.
- Git is installed and maintained on your local system (rather than in the cloud), GitHub is a cloud based repository hosting service.
π π Congratulations π π
If you liked this tutorial consider supporting by Liking and Sharing this article.
You can also Buy Me a Coffee
Follow me on Twitter
If you want me to make a tutorial on any computer science concept then leave the topic down in the comments.
(I might make tutorials on git commands/GitHub workflow if people ask for it.)
References
Top comments (25)
This was fantastic!! I have to admit that it took me waaaaaaay too long to grasp this concept:
"What is the difference between git and GitHub?"
"Git is a command line tool while GitHub is a website"
What an awesome article for beginners and experienced folks alike!
Thanks for the feedback Mikel.
Such comments encourages me to work hard on the content ^_^
Good article Nirbhay. π
Explained the details so well using memes and analogies. ππ
Loved your way of writing.
Thanks for the feedback Ashwinππ
I am glad you liked it
Nice post Nirbhay, I have a created a cheat sheet for interns. Usually I handover it to them when they join the company.
gsin11 / git-cheat-sheet
GIT commands cheat sheet
GIT Commands Cheat Sheet
Project is about GIT commands
CREATE
LOCAL CHANGES
COMMIT HISTORY
BRANCHES & TAGS
β¦Thank you very much for sharing this resource with us Gurpreet. Much Appreciated :D
What a story, just awesome...
Thank you for the feedback :D
Awesome Nirbhay ππ I love the analogies! They explain stuff so much better. I am a fan of the images tooπ
Thanks Manaswiniπ
I am glad you liked itπ
Congrats on submitting your first article! Lots of useful info here. Well done!!
Thank you for the feedback! Means a lot to me π
Good job π
Thanks for the feedbackπ
It's very easy and quite good article for the beginners.
Simple and easy way of explainations good use of pics and metaphorsπ
I will definitely recommend to my fellow buddies who wants to learn Git and GithubβοΈ
Good to see you on here Nirbhay. Nice article π
Thank You very much for taking your time to read it and giving your feedback. Means a lot to me π
Very good article. I like the way you expressed in a very simple way.
π€π»πππ»ππ»
Thank you very much for the feedback π