Basic Git Analogy for Contributing to Open Source Project
Git and Github
Here in this article, I am sharing a real-life analogy for understanding basic Git required to contribute to an open-source project.
Suppose there are 2 people A and B in a college.
A is one of the popular professors in the college and is known for his amazing teaching style. Further, he has also published a lot of research papers and thus is also popular among the research community too. Being popular among the students for his teaching style, he is writing a book so that he can share his knowledge with masses. As of now, he has written a few chapters in the book.
B is a freshman (first-year student) at the college. Being a freshman, B is good with English but not much into technology. Being a freshman, B has a lot of free time but is not much into technology. So, he plans to do some work and starts talking to his seniors. From that, he heard a lot of praises about A from his seniors. So, he plans to meet professor A to indulge in some work. He thought that A would provide him with some work based on somewhat technical/non-technical skills he has.
Professor A teaching a class
When A meets B, A wasn’t much satisfied with the technical knowledge of B but he was astonished by the English language skills of B. So A thought that B would be could help him in editing the book which he is writing.
Student B meeting Professor A
A then prosed this to B. Further, he mentioned that if he helps in editing the book, his name would be mentioned in the book. After some thinking B agrees to work on editing the book thinking that this would at least build some connection with the professor. Further, B thought that he would gain some insights from reading the book.
So after the mutual agreement on working on the book, A sends an editable e-copy of the book which he has written to B over his e-mail.
E-Mail of e-book from Professor A to Student B
Fork a Github repository:- The process described above of transferring of e-copy of the book from A’s Email ID to B’s Email ID can be seen as Forking. Forking a project is similar to this i.e. having an e-copy of the current version of the project on your own Github profile. Forking a Github repository can be seen in the animation below.
Forking a Repository on Github
Now after having an e-copy of the book on his e-mail B plans to work on it. But being in the first year of college, unfortunately, B doesn’t have a laptop so that he can work from home. So B takes the print-out of the first chapter so that he can work from home even without a system.
Student B taking printout o the e-book to Work from Home
Cloning:- This process described above of printing the book to have a hard copy so that work can be done at home can be seen as Cloning. Cloning a GitHub repo is similar to this i.e. downloading the project locally on the system so that changes can be made to the project. Cloning a Github repository can be seen in the animation below.
Cloning a Repository from Github to Local System
Now B starts working on the book. So just in-order to be 100% precise in the work B first makes the changes with pencil and then on completion of the page he rechecks it and then finalizes it using a pen.
Student B working on editing the book at home
Adding and Committing the changes:- This process described above of making the changes in a step by step procedure is known as Adding and Committing the changes. This process of finalizing the changes can be visualized as adding and committing the changes. Adding the changes in a project refers to making the changes and Committing the changes refers to saving the changes with a message. Adding and Committing the changes on a Github repository can be seen in the animation below.
Git commands for Adding and Committing the changes
git add . git status git commit -m “Commit message here”
Now after completing the editing of one of the chapter, B goes back to college and opens the e-copy of the book which he has on his mail. After this, he updates the changes from his hardcopy to the e-copy.
B working on editing the e-copy of the book from the changes that he did at home
Pushing the Changes:- This process described above of updating the e-copy of the book which B had from a hard copy can be seen as Pushing the changes. In this case, after pushing the changes would only reside on the e-copy which B has on his system. Pushing the changes is similar to this i.e. when we send the changes which we have made locally to the repository which we have forked. Pushing the changes to a repository can be seen in the animation below.
Git Command for Pushing the changes to Github
git push origin master
After putting all the changes on the e-copy of the book on the system, B sends the updated e-copy to A via an email and asks for a review.
B sending the updated Copy of E-Book to Professor A
Sending a Pull Request:- This process described above of sending the changes to A via an email can be seen as Sending a Pull Request. Sending a Pull Request is similar to this i.e. when we send the changes from our GitHub repository to the original GitHub repository so that the project owner can see and review the changes. Sending a Pull Request can be seen in the animation below.
Sending a Pull Request on Github
After sending a Pull Request, A receives the changes which were made by B. Now A takes a look at them and reviews it. A is mostly satisfied with the work of B except a few of the changes. At some of the places, the update from B had changed the meaning of the sentence. So he sends a mail-back pointing to those issues.
Professor A reviewing the changes made by B
Reviewing a Pull Request:- This process described above of looking and reviewing the changes from B can be seen as Reviewing a Pull Request. Reviewing a Pull Request is similar to this i.e. when a PR is sent the owner can see all the changes which have been made in the code. If the project owner is not satisfied with the changes or something is missing he can comment about the same in there itself. This process is repeated several times to ensure the quality of the final project. The process of reviewing a Pull Request can be seen in the animation below.
Reviewing the code changes on Github
Once the review process is complete and A is very much satisfied with the work of B, he updates his book with all the changes which were made by B in his main book. Further, being happy with the work of B he also mentions his name in the book to reward him for his work.
B being appreciated for his work by Professor A
Merging a Pull Request:- This process described above of accepting the changes from B can be seen as Merging a Pull Request. Merging a Pull Request is similar to this i.e. the process of accepting the changes proposed and including the changes in the main project. The process of merging a Pull Request can be seen in the animation below.
Merging a Pull Request on Github
Similar to the way the name of B was mentioned in the book for his contribution in the book, contribution in an open-source project is also mentioned. Even a change in a single line of code counts as a contribution and is listed in the contributor’s page. You can see the list of contributors of one of Open Source Project below.
List of Contributors on a Github Project
And yes, getting a Pull Request merged is not an easy task, after getting a Pull Request merged, its time to celebrate.
Partying after the Pull Request gets accepted
I hope by now you would have got a bit more of understanding of the complete procedure of how to contribute to a project.