INTRODUCTION TO GIT AND GITHUB
Tags: github, git, webdev
Published: 2023-09-16 20:00:05

Outlines: 
●What is git?
●Advantages of using git.
●What is github?
●Advantages of using github
●How does git even work?

Often, in programming, regrettable changes are made to our files. There is hesitation to experiment more with projects for fear that it might ruin what was originally planned. Reversing those changes back to the previous state might be too annoying and or time-consuming. Collaboration with other developers is stressful because file sharing can be bothersome, but not to worry, Git can fix all of that.

What exactly is Git?
According to Wikipedia, Git is a distributed version control system that tracks changes in any set of computer files, usually used for coordinating work among programmers who are collaboratively developing source code during software development. 
https://en.wikipedia.org/wiki/Git#:~:text=Git%20(/%C9%A1%C9%AAt/,source%20code%20during%20software%20development.

In simpler terms, Git is a system that tracks changes to your files, allowing you to access any version of these files whenever you need. It also provides an environment that facilitates seamless collaboration with other developers on your project. 
What are the advantages of using Git?
You might be thinking, "I go through my projects just fine with little to no issues, is there really a point to having Git?". There are numerous benefits you might not be aware of, a few of them are as follows:

●Low storage: It helps store all the changes made to your file in one directory(folder), enabling you to save space on your computer.
●Easy code management: Git provides a simple and effective way to manage code as it tracks all changes made to files making it easy to access any version of said file at any time.
●Encourages experimentation: By leveraging Git, you can access any file and it's previous versions, and experiment with your code without the fear of losing the information or data.
●Facilitates collaborative development: Git allows multiple developers to work on the same project with little to no issues.
●Open source: It is freely available for anyone to use as it is an open-source project.

What is Github?
According to Wikipedia, it is a platform and cloud-based service for software development and version control using Git, allowing developers to store and manage their code.
https://en.wikipedia.org/wiki/GitHub#:~:text=February%202023,store%20and%20manage%20their%20code.

In other words, github is an online platform that hosts and manages our work already saved to git.

What are the advantages of using Github?
Already having Git does not negate the need for Github, a few reasons being:
●Collaboration: It makes collaboration easier as developers are able to work on the same code at the same time.
●Easy sharing of code: Github facilitates easy sharing of code with other developers as it can host projects with the user's permission to be used by the public.
●Security: Github ensures the user's code is protected from unauthorized access with its various security features.
●Resolves issues: Github has a built-in feature that automatically tracks and resolves conflict in the code.

How does Git work?
The feature of Git used mainly by developers is the recording and storing of the changes made to their files, which sounds incredibly convenient, but how exactly does this happen? It is done by committing repositories.

A repository is the folder containing the files to be tracked by Git. It is important to note that having various repositories saved to git won't merge or disturb your projects, regardless of how many repositories you have, they will all be tracked individually.
Where the Git file resides significantly affects which files would be tracked.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2n23ypg40orh88145pq0.jpg)
In the above image, the git file is added to the main folder(project folder), so because of this, Git tracks all the items in the main folder, including the subfolder (IMG) and all the files in it. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4pngttshw7eu1fks7in.jpg)
In the above image, the git file is added to the sub folder in the project folder(Javascript), so Git only tracks the files in the subfolder. The other files, as you can see, remain untouched by Git.

A commit is a stage in your code saved to the repository that enables you to go to the saved stage whenever you please. You can think of commits as safe points in your project.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vbwd58ld8nix4q2d94aq.jpg)
In the above image, you can think of the boxes as commits and the line passing through them as code. The four boxes are all safe points you can jump back to whenever. If you feel like you don't want your footer anymore(Added footer), you can take a step back to the safe point before then(Change all fonts), and if you end up changing your mind about the footer again, no worries! Just jump back to the 'Added footer' commit, and you can have your footer back.
There are three stages of committing: modified, staged, and committed.

Modified: This is when you've changed or added to your code since the last safe point. 
Staged: By adding a file to the staging area, you choose or acknowledge a potential safe point to which you wish to be committed. Staged files are not the same as committed files; they are only files you're considering committing.
Committed: By committing a staged file, you are officially crowning your current code as a safe point you can return to at any point you please.