Intro to Git


Yeah yeah I know it's difficult, trust me it is or atleast it was for me! I am absolutely an amateur if you find any mistakes maaf kar dena(forgive me in Hindi). So when I started my college in a tech branch , as an enthusiast I researched about this world and fell into the feet of GitHub. GitHub was like roaring at the time around me (mostly because I wanted to learn about it and was finding no solutions, 'how to') and now too! So it was really difficult for me to learn about it! But now I have some fair idea about it ,and I am going to share it with you and hope it helps you in one way or other! So git is a version control tool, it also helps group to work on a same project simultaneously. As the name suggests it is a version control that means it controls all the versions (of your project, code or whatever!). It is a command language,that means you have to type certain commands manually, for it to work accordingly. It can be helpful when large communities are involved in a project. So when you and your friend have certain ideas to involve in the same codebase ,and have changed the code accordingly now when you need to add those changes to the main codebase there can be lots of conflicts that can occur for example, at least, these days nobody's got time to wait for other person to add their changes ,like everybody loves parellelism ,what if I tell you that you both can add things,test and do your own work on the code simultaneously. Yes that's where git comes in! Git allows you to creat a copy of the main folder(repository in fancy dictionary), where all of the nessecary things lay, on your own computer. You can add changes to your copied code, (that is not going to change the main code), test it, run it and then if all goes well push it to the main code that means add those changes to the main code! Also as I said git is "version control" tool ,let me try to explain it to you, suppose you write certain changes to a large code and unfortunately those changes put in you in trouble,and not work and you think shoot the "earlier verion" was better well you can delete those changes manually hunting all the places you made a change but it will be a lot of chaotic work well all of these are in past, now we have Git! You can switch to previous versions pretty much at the rate of a blink. To attain all of these features of git you need to learn certain commands. So let us have some discussion on some commands;
•git clone {URL}: this commads creates a copy of the repository (folder in other name) of a particular project from a host(Eg GitHub) to your local device. That is whatever URL you mention should be from the host. Whatever changes you make to this "clone" will not be added to the main code unless you command it to.
•git add {file name}: it is like setting the stage for recording the changes. So when you change your code it is not officially the part of your code yet, to do that you have to add that file into the index, index is place where all the staged (the changes which are officially a part if the code) changes are recorded. That is it "adds" changes to the specified file and also this is recorded in the "staging area"/index(specific to the specified file). So before capturing the changes you have to be sure of the changes you have made! So this command basically sets stage to recorde the changes made. In other words sets stage for the next "commit".
•git commit : A vague idea is that of taking a snapshot with the current state of the file/code present in the staging area. So obviously it does not take a picture, so what actually happens is that when you give this command , whatever staging area is holding currently, is put into the repository's commit history, as the name suggests ,a place where all the history of commits are recorded, allowing you to track changes, review the history, and go back to previous versions if needed.
These are some basic, fundamental commands used. There are many other commands for various works like going back to earlier verions , to add changes in your system to the main code present in the host (git push) ,to acquire new changes made from host's repo to your own(git pull). You can also create a different "branch" (basically a copy in a new directory)(git branch {branch name}) this allows you to change things in a very usefull way ,suppose you want to add a new feature and you found a mistake in your base instead of crippling and rubbing it all off ,you can create a branch, it is safer and more convinient ,you can change the base and also extend it and any new feature. When you want to add all of these changes to the main version you have a command git merge with syntax, git merge {branch name} ,which means it is going to merge the current branch that you are at ,with the specified branch. That means it "merges" one branch with the other, more specifically current branch to the specified branch.
There are several other commands that are usefull ,hope I have set a base stage where you find it easy(-ier) now to research about! Hope I have not made many mistakes ,if I have feel free to name them!
Thanks for reading!
Subscribe to my newsletter
Read articles from Priya Mannur directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Priya Mannur
Priya Mannur
Exploring..