Git + Github: The basics you should know
A simple explanation on Git and Github for newbies
What is Git & GitHub and why is everyone using it?
Basically, Git is a distributed version control system that lets you manage and keep track of your source code history. GitHub is a cloud-based hosting service that lets you manage Git repositories.
Since we are clueless newbies trying to figure out how these things work, We might ask what a version control system and a Distributed Version Control System(DVCS) are. Simply putting, It is a system for controlling the changes to computer programs or documents or any sort of information. And distributed means that each developer working on the same project has a full copy of the code including its version history(gives you access to old copies of the files, its creators, size, etc) on their own computers.
For more clarity, Imagine you are working on a collaborative project report with your friend, You made a decent introduction to it and named it project_trial1 and you emailed it to your friend to add to it, he made some basic changes to the intro and added some content to it and named it project_trial2 and he sent it back to you. This tedious process continues till the end and then you realize some of the deleted parts were might actually come to use for the beauty of the final edit. Then this process again becomes an inefficient way to add and edit changes in a project. After this, they may store their document or work in a cloud(eg:- Google Drive).
Now think of the number of members increasing in your team and the problem you are working on is pretty complex and the changes made to it are more frequent. Then what can we do?
Again think it in the case of big tech companies, a large number of teams will be working in the same code, solving the same problem. How can we tackle this problem?
Here comes our Git.
We can simply install Git on our machine, then we can upload our code to the cloud.
Here the “cloud” is GitHub, which will host our code. Hence Git is a mechanism to upload our code, whereas GitHub is a place to store this code and access it later from any other device.
So, I think you got an outline of what is Git & GitHub.
Who created Git and What’s the story?
It is created by Linus Torvalds (Creator of Linux) in 2005. He originally created Git to help manage the task of developing the Linux Kernel.
During the early years of the Linux kernel maintenance, changes to the software were passed around as patches and archived files. In 2002, the Linux kernel project began using a proprietary DVCS called BitKeeper.
In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tool’s free-of-charge status was canceled. So they created their own tool based on some of the lessons they learned while using BitKeeper and developed Git which is a free open-source system available for installation on Linux, Windows, and macOS.
Get Josephine’s stories in your inbox
Join Medium for free to get updates from this writer.
Pretty cool right? Now let’s further dive into it.
Github Workflow
Some fancy terms for simple things in Git
- Repository(Repo): The place where the coding projects are. It can be local to a folder on your computer, or it can be a storage space on GitHub. You can keep code files, text files, image files, you name it, inside a repository.[For example, You can upload a folder called project_trial consisting of your project_trial1 and project_trial2 documents into this repo.]
- Local Repo: One on which we will make local changes, typically this local repository is on our computer and it is hosted online.
- Remote Repo: Version of our project hosted on a server that is accessible for all team members.
- Commit: A commit is an individual change to a file (or set of files)which saves to your local repo.
- Push: It is how you transfer commits from your local repo to a remote repo.
- Pull: It is how you fetch and download content from a remote repository and immediately update the local repository to match that content.
- Working directory : It simply refers to the folder in which the files are stored.
- Staging area :It’s the place where we store the files that are going to be a part of the next commit.The working area is like your scratch space, it’s where you can add new content, you can modify delete content, if the content that you modify or delete is in your repository you don’t have to worry about losing your work.
- Merge: The main branch incorporates all the changes you’ve made to your branch (Explained below in detail).
- Branch:A branch is a version of your repository, or in other words, an independent line of development.The git branch command lets you create, list, rename, and delete branches.Each repo starts with one branch, a main branch called “main”.
Here, We can see the main branch going through the middle.While working on a project it is always advisable to create a new branch and work on it instead of directly manipulating the master branch as there is a high probability to mess up the entire project when we try to add a new feature.
So, In the new branch we’ll get an exact copy of the master branch, then we continue experimenting and editing our code as per our wish.And if we implement the feature successfully , we can merge the new branch to the master branch.Hence keeping the master branch void of errors.
So what happens if two or more people edit the same line of code?
Here comes the “Merge Conflict”. It is the inability of Git to automatically resolve the differences in code between two commits.Git asks us to pick a best version by showing us the both versions of the line of code.Therefore we can fix that conflict simply by knowing that we are overwriting another person’s code.
So, to sum it up:-
- We can pull the repo on the GitHub which was pushed by someone.
- Then we can create a new branch to work on it.
- Then we commit to save the changes and we push it to the repo.
- After successful feature implementation we can merge our branch to the main branch and push that to the repo.
- If someone changes or overwrites our code merge conflicts arises and Git will inform us about this and we can solve it easily.
So, this is the gist you must know about Git and GitHub.There is still lot more into it, if we dive deeper. I hope this helped you to enter easily into the basics Git and the whole workflow of GitHub.






