Git : The Introduction
Have you ever start wondering what the heck is Git and why is everyone talking about it ? Do you often see posts on social media and groups about git and say “ yeah , i should someday learn about git ’’ ?
Git ? GitHub ? GitLab ? What is this mess ?
Well , don’t you worry dear ENSIASte , because in next few minutes , you’ll be able to know The What , Why & How of Git so you can flex on your friends too :)
So what is Git ?
Git is Version Control System (VCS) , a piece of software that helps you track and manage different versions of our project .
Let me explain what this means , but first let us define first what’s a project ?
A project can be defined ( in my opinion ) as solution to a problem , a solution that covers a need and this solution is simply a bunch of features ( or functionalities ) .
So when you’re building your software , you start adding one feature after another , it’s more like the 1st feature is version 1 of your project , once you add another feature , it becomes version 2 and here comes Mr Git and start tracking the different versions( 1 & 2 ) of you project , so you can swing back and forth between them easily .
Git , In a nutshell , is a record where you can save different versions of your projects .
Why Git ?
Now that you have an idea about Git , we can talk a little bit about why it is important for you to learn it .
- Professional jobs and career .
According to the latest StackOverFlow Insight , more than 80% of professional developers use Git . It is commonly used in both commercial and open-source software development .
If you ever get a job or an internship , you will almost definitely be using Git on a daily basis in order to keep track of the project you’re working on .
Story Time :
A friend of mine once was an intern in a company , he was given a certain job to do and after he finished , he copied the folder on a USB and went to his boss with a red face ( b wjho hmer ) to give him the USB stick with a big smile :D .
His boss started laughing , lucky for him he didn’t get fired HHHH .
- Team Efficiency .
Git will incredibly make your you team work easier , as you can see the entire timeline of different versions of the code . It gives the ability to observe changes , history , new features and progression of your team mates in one place .
Using branches ( which i will talk about later on this article ) , you can safely change anything in the code without the risk of screwing up the production . This allows synchronization of the code between different people , This so OP right ? :D - Contributing to Open Source .
Github (i.e Gitlab, Bitbucket …) is a code hosting platform using version control with Git , it allows you to host your project on the cloud , as well as getting involved in other open source projects . It is indeed a great way to show you coding skills and prove to recruiters your competence , specially if you’re a self-taught.
How to Git ?
Before diving in git commands , we need to understand first a few key concept about Git .
- Repository
Repo is just a fancy way to say folder or directory ( another fancy way to say folder xD ) , but not any folder . It’s that big folder that you named “ Projet X ” in your desktop , containing all files and images and ( you name it ) that you used in your project .
So basically your Github profil is a set of repos , one repo per project . - Branch
Branching is one of the amazing features that Git offers , let’s tackle this by an example : let’s say that you work with a company and your boss told you that to fix some bug in a project , alright ?
You’re not going to stop the whole production just for that , aren’t you ?
That is going to cost the company so much , specially if it’s a high caliber company , we’re talking about thousand of dollars or even millions ( no body f*cks with the money , you know … )
So what you can do ( thanks to git ) is to create a “virtual environment” , where you can experiment new things without the risk of affecting the original code , this VE ( virtual environment ) is called a branch , it’s an isolated copy of the whole code . So after finding the bug ( in our example ) you can merge the two branches ( the original and the one you just created ) into one branch and all the changes will be applied .
Yaaay … Git is so OP ! right ?
Side note : By default , the main branch that comes with a new repo is called master branch and then you can create as many secondary branches as you wish .
3 . Commits
When we say we’re committed to something , it means that we’re sure and absolutely positive about it . Same thing here , when you commit a branch , you save all the changes you’ve made and git creates a unique ID (called “hash ”) that allows you to keep record of the specific changes commited along with who made them and when and an optional brief description .
Dear ENSIASte , i am happy announce to you that , now , in this moment , you’ve learned the vocabulary that you need to get started with git .
The rest now is just a bunch of commands , how to do this and that , nothing to worry about my friend , i got you covered .
How to use Git for Moroccans
About this part , i couldn’t find a better non-boring tutorial other than Yasser Douslimi ’s gist , Enjoy :D .
Initializing a git repo
git init
Hadi dima kadar flowal bash git i9ad lik l omor flowal fash kat creer dossier
Connecting to remote repo
git remote add origin <LINK DIALAK>
Hada hoa liki 3tik t copyih ya ima f github wla gitlab wla bitbucket
Pulling your project from github
git pull origin <L BRANCH>
Normallement katkon l branche dialak master walakin t9ad tkon smitha likan
Adding files to stage ur commit
git add <file path>
t9adi diri add * bash t ajouter ga3 les fichiers
Commit your changes
git commit -m "shi message kima kan"
hadak l message hoa le but dial changement dialak
pushing ur changes to remote repo
git push origin <BRANCH>
normallemnt l branch kikon master
Creating a branch
git checkout -b SMIYA
hadi kat creer l branch o kat switchi lih en meme temps b dik -b
Cloning a repo
git clone <Repo link>
l far9 mabin clone o pull hoa anak la cloniti katakhod les fichiers 7arfyin ama git pull katkon nta engagi fl project
(When u first install git) Signing in to remote repo
git config user.name <smitak>git config user.email <email dialak>
I’ll leave this here 😊
Yay … you’ve made it till here , i am so happy that you stayed with me until the end !
I hope you find this article helpful , i really appreciate your time .
That’s it !
BIG SPECIAL THANKS to Yasser Douslimi for the last session of the IT Training Cell about Git , we’ve learned a lot from him and he is the reason that i wrote this article .
MAY WE MEET AGAIN :D