If you are relatively new to programming, there comes a time when you come across Git and GitHub. This may be when you want to deploy a project on the internet, share your code, collaborate on projects with other developers, help someone else with their code, etc.
Jumping on a Git tutorial without understanding the purpose of Git can be confusing. In this article, I will explain why tools like Git and GitHub are essential in the software development ecosystem, using beginner-friendly analogies.
Life Without Git
Let’s assume you are working on a project using your personal computer. You will have a project folder that contains your code files and configurations on which you have been making changes.
Now, let us simulate a week’s work:
On Monday:
You wrote the code for four new features - features A, B, C, and D.
On Tuesday:
You fixed a bug, bug X.
On Wednesday:
You removed two features, B and C, because they seemed unnecessary, and you deleted quite a lot of code in the process.
Thursday:
You realise that one of the features you deleted from your code on Thursday, say feature C, is an essential feature, and you need to get it back.
A possible solution is to rewrite the code, but remember, it was a lot of code, so that would be stressful.
Let’s assume you made a copy of the files before removal (probably as a precaution). You’d still go through the “stress” of copying the code from the “backup” and merging them with your current work files; this process is one of the reasons why Git exists.
Lastly, on Friday:
While testing your code, you realise that the bug you fixed on Tuesday introduced other disturbing bugs, and you wish to undo your “bug fix”. There isn’t much that Ctrl + Z can do to help in this situation.
Wouldn’t it be nice to have a magical time travel machine in these scenarios? That can easily take us to previous versions of our project, as they were at a specific time? Think of Git as that time travel machine.
What Does Git Do?
Git provides a "version-control system". This means Git helps you manage or control different versions of your project.
How Git Works
Managing your project using Git means Git will keep an eye on files and directories in that project— tracking.
Git notices the changes made to tracked files in your project. These changes are then “committed” into Git’s history.
When changes are committed, Git takes a “snapshot” of the files, so it remembers the exact state of the files at that time, just like a photograph.
You can have as many commits as you work on your project, and when the need arises, you can view or restore your files to a previous commit. Git will give back your files exactly as they were when you made the commit— the required time travel.
Also, with Git, you can easily switch between different versions of your project, compare and track the changes over time, collaborate with other developers and lots more.
Here’s an illustration to help you visualise the timeline.
What about GitHub?
Git has numerous features that help simplify development; another is making collaboration organised.
Imagine you are working remotely with about ten other developers on the same project. Without Git, there will most likely be a lot of confusion and mishaps.
- When multiple people work on the same file, how is this sorted?
- What happens when the file you made changes to gets deleted on someone else’s computer?
- How do you know who made a specific change and when this change was made?
- Most importantly, how is everyone’s contribution combined in the project?.
Will everyone attach their work files in an email and send them to a “manager” who then downloads and sorts it all? And does this hectic process have to be repeated for every little change? Hopefully not.
As earlier mentioned, Git helps to keep collaboration organised.
A project being managed with Git is known as a repository, and this is where GitHub comes in.
GitHub helps to host your project repositories on the internet. Your project files are stored on the internet, making them accessible to remote collaborators.
Contributors to that project can have a local copy of the project on their computers, make changes on their local copy and “push” those changes back to the online repository.
With Git and GitHub, changes pushed from several collaborators are easily organised, combined and managed. Everyone with access to the online repository can see these changes and update their local version. Cool right?
Here’s an illustration to help you visualise:
Conclusion
Git and GitHub have many other incredible benefits. I hope you now understand the purpose of Git and GitHub and why they are essential tools in development.
I should mention that there are other version control systems and hosts for repositories.
Goodluck learning.
Top comments (1)
Hi, I’m the owner of GitBulk. If anyone in interested in replacing code on many GitHub repos easily without having to write any command visit gitbulk.com
Some comments have been hidden by the post's author - find out more