Git: Why, How & What?
I have been using git for past 5 years (started in 2017) of my engineering career. Throughout the journey I have experimented a lot, I have messed up branches, repaired them, deleted them and many a time have kept them untouched, but the most important thing is that I have utilized the tool for almost all my projects and learned a lot. In this article I have put down my understanding of Git.
Why?
So the major and important question any before adapting anything new is, Why?
Imagine this, you and two of your friends are working on a .txt file. For keeping this simple, let assume you are writing alphabets, one on each line. You are tasked to write letters A, B and C, the second is assigned to write D, E, and F and the third one is going to write G, H and I. So far so good, you have your plan ready and now its time to execute. Each one of you took out your laptops and started with it.
Now a plan is only as good as its execution, so you start writing on you own machines
You write
a
b
c
The second guy writes
d
e
f
And the third guy writes
g
h
i
Great, now both the guys mail their files to you and you sit and stich them together
a
b
c
d
e
f
g
h
i
Great, everything was smooth until this point, now the new task is to not just write alphabets in small case but also in capital case.
So again each writes their part and sends it to you and then you again stich that.
This process will be followed every time there is some change. Now imagine when you write codes for you website, app etc, this method will fail.
- You must always know what changes the other person has made
- You will lose track of which file, sent over mail, has what code
- You will have to send everyone the latest, manually merged code
- You want to revert back some change did by someone else, it would just be a nightmare.
- If something had to happen to your machine, god knows what the latest code was!!
These are only some inefficiencies that I have mentioned. You can imagine the kind of hell you would be in!
So to address these problems, imagine if you had a tool, on which all the team members could log all their respective changes, keep track of changes done by others, go back to any logged change anytime, the tool also gave you an interactive and intuitive way to merge the codes and on top of this, it also had a safe and secure online space where everything was tracked, merged and maintained.
How?
Now how does git exactly solve our problems?
So as mentioned above Git is a tool the is used to maintain the codebase of your project and help you collaborate with your team efficiently.
So now imagine the earlier scenario again, where in you wrote
a
b
c
Now since you are using Git, you will put this file in you Git repository (a virtual space), the second member will pull this file in his local machine and add his changes and again push to Git.
The file on Git now reads
a
b
c
d
e
f
Now even if you don't have the latest change done by the other person in your local machine, you can still do more of your changes, and then when you are pushing it to Git, the service will prompt you saying that there is one logged change, between the time you last updated and now, thus helping you to merge the file by pulling the change in your local machine first and then pushing everything on again to Git.
Thus the file will now have
Aa
Bb
Cc
d
e
f
Also, whenever you deploy this file, you can point it to your Git service, from where it will get the latest file having everyone's contribution.
What?
"Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency."
Git is just a tool or a framework, to use Git in actually you have to use GitHub/GitLab/BitBucket etc services that used to manager Git repositories.
Disclaimer: the above piece that I have written is very crude and unreal. The real-life usage of Git, its features and functionalities are widely explained in many YouTube video and online blogs.
Please write in comments about your thoughts on this article and let me know if you guys have any article suggestions for any topic related to "software engineering".
Top comments (0)