Getting Started with Git & Github
What's the difference between Git and GitHub? To answer these questions, we need to first understand What is Git and GitHub?
What is Git?
Git is an open-source distributed version control system for tracking changes in computer files. It also allows many developers to work together. Its main benefit is branching, which means many developers can create many branches based on their needs, parallel to the main branch.
Now you'll ask what do you mean by the version control system? So, let's find the answer to this.
What is Version Control System?
A Version Control System (or VCS) tracks the changes to a file or set of files over time so that we can recall a specific version of the files later. It includes:
- Which changes were made?
- Who made the changes?
- When were the changes made?
- Why were changes needed?
For example, any development project doesn't come into existence at once. They're built by writing code again and again and again. We need to track all the changes of the code so that in case of any error we can revert to the previous version of the file.
Now let's understand why we call Git a distributed version control system (or DVCS)?
A Distributed Version Control System solves many earlier problems of version control. Earlier VCSs manages the files either locally or on centralized servers, which can cause complete data loss in case of any server or disk error. But, in DVCSs all clients can have a full copy of the repository including its full history. Thus, if any sort of data loss happens, it won't affect the whole system as another system has the same copy.
Let's understand what are the problems which Git solves:
- Changes made to a file or code which you wanted to revert later.
- Lost a code or file.
- Backup of the codes.
- Maintaining multiple versions of a code or file and analyze the differences.
- Sharing your code or work with other developers on the same project.
- Tracking work done in detail like who and when worked on a piece of code.
- Experimenting with your code without messing with the production version.
Git's Three States:
Git has three main states that your files can live in: modified, staged, and committed:
- Modified means that you have made changes to the file but have not committed it to your database yet.
- Staged means that you have added the modified file in its current version to go into your next commit snapshot.
- Committed means that the data is stored in your local git database.
These three states lead us to the three main sections of a Git project: the working directory, the staging area, and the local Git directory.
The working directory is referred to as that directory where the command
$ git init was executed.
When we add a new file to the working directory the changes are untracked, so to track the changes, we need to add the files to the staging area using the
$ git add command, where the changes are stored in
.git/index file. Later the staged changes are committed to the local repository using the
$ git commit command.
While committing, it is important to add a meaningful message string using the
-mflag. If missed, a default editor opens asking for comments.
Now we have a basic understanding of Git workflow and working, we should understand GitHub.
What is GitHub?
As we now know, Git mainly works locally. Now you can ask, you said earlier that multiple developers can work together on a single project, but how can multiple developers work together on a local project.
Now here comes the contribution of GitHub, GitHub is a website where we host our local repositories so that other developers can have access to it.
GitHub is more likely a platform where many Open Source projects are hosted and anyone can contribute to that project worldwide.
GitHub uses the same Git data which are stored locally but represents you all visually so that you can use the information easily.
Git and GitHub are two different things but both are somehow dependent on each other. Git keeps track of changes & historical backup of the project locally whereas GitHub hosts the same Git information so that you can share your local project with the world.
In the next part, I will share how you can install & configure Git using CLI and also GitHub Desktop GUI. I'll try to cover all the aspects of Git & GitHub in the upcoming posts.
If you find any mistake in the post, please do let me know in the comments, I'll update that surely.