Wednesday, October 7, 2020

October 07, 2020

Understanding Git Commands [Simple & Quick]

As a developer, you may feel that any changes that you made on your project should be documented somewhere. Especially, when working in a team one must know who made what changes at which time etc. 




Moreover, since many developers are working on the same project it may result in a conflict or there may be some project sync problems. Fortunately, a solution to these problems exists in the form of "Version Control System".


As the name suggests, A version control system is a software that has the responsibility to control/manage the versions i.e changes to the system.


One of the most popular version control system which is used all over the world is "GIT".


Git is a version control system that operates on different commands. In this article, we will discuss some of the important GIT commands one by one and will see how they can be used in your project.

So here we go.


GIT COMMANDS:

Before starting to talk about GIT commands, I will present an analogy that will help you to understand them well.


"Suppose you have clothes scattered on a bed. You have to put them in different baskets according to their category, then take the baskets to the nearest Locker and put the clothes from each basket into the locker".


1. GIT INIT:

Project on which git works is called a repository. To make your project a git repository you have to initialize git on it.


git init:  This command will initialize your project as a git repository. 


After you execute this command,  A hidden folder named .git will be created in the project root folder.  This folder will contain all the files required to make git work on the current project.


This command is like telling git:" Hey, Git initialize my project as a repository so you can start to track files in this project"


GIT will say: "Ok, let me create a git folder in your root folder to start tracking"


This git repository is also called " Git Working Directory"


2. GIT ADD:


We have told git to make our project as a git repository but we haven't told git about on which files the changes should to tracked. This git command is like putting clothes on the bed without being placed into the basket.

To tell git about which file changes should be tracked, we have to put them in what we called a "Staging Area". Any file on which changes needed to be tracked should be in a staging area. Think of a staging area as a bed where clothes needed to be placed.

Now To add files in the staging area, write this command: git add file-name

But if we want to track all files on a project instead of a single file then use this command: git add  .

This command will tell git to add all files of the project into the staging area.

Now after executing the above command we have placed clothes on the bed. It's time to put clothes in their respective baskets like shirts into shirt basket etc.


3. GIT COMMIT:

Commit simple meaning is a change. Remember git goal is to track/revert changes? To do this we have to make sure a change is saved so we can revert it whenever we want.


So to do this we use this git command. It will create a copy of this change. This is like scattered clothes on bed but we haven't put any clothes in the basket yet.

Command: git commit -m "Something Changed"

After executing the above command, our change will be saved. This is like clothes on the bed which is being placed into their respective baskets.


4. GIT PUSH:

If a project is located on a remote server then we have to make sure our local changes should be sync with the remote directory.  Here local changes mean all commits of a project as described above.

We have to push any changes made in the local directory to the remote directory. Here changes mean all commits of the project.

Before moving the commits to remote, we have to tell git about the location of the server.

To do this use the below command:

Command: git remote add origin https://github.com/Username/app.git

As the GitHub is the most popular git repository, we are using it as our remote location. But If your project lies on different hosting then you should be able to find the option of "Git Version Control" from your Cpanel where you can find the remote address of your project.

Now we have added the remote address, it's time to place the clothes from the basket to the locker i.e push project changes to remote.

Use the command: git push


4. GIT PULL:

To fetch the latest commits from the remote server use this command: git pull

Conclusion:

Still, confused? Well, there is a solution in the form of GUI for those who don't want to fight with git commands. The most popular one is the Github Desktop.

For those who prefer to write Git commands can download Git Bash

I hope these basic concepts about the working of GIT commands will help you to better work with your team and to better manage your projects. 


HAPPY CODING!


Tuesday, March 19, 2019

March 19, 2019

What is Composer in PHP/Laravel? How to Install PHP Composer


Most of you already heard a term "Composer in PHP" but only few of you actually know what actually it is , composer advantages, how it works , how to install composer and finally it’s different commands like composer install, composer update. Well don’t worry as this article going to answer all your questions regarding composer. Moreover, you will also see the practical example of using composer in Laravel.

composer-in-php-laravel


Before understanding about composer in PHP we have to first know about what is "Dependency management". Dependency management simply means managing the dependencies on which the project depends.

Suppose you are working with images and you need a library to manipulate the images in a better and easy way like creating, editing images, adding watermarks on it etc. To achieve this task we can use PHP library named "Intervention", We have to download the library and manually adding this in our code.

For small projects adding libraries manually is not a huge task, But if you have large projects then manually adding them is not a right way to do. Moreover, if you are working with PHP framework like Laravel then you know that Laravel uses different libraries for different purposes i.e authentication etc. Because of the lot of dependencies on which Laravel depends, Recommend way of installing laravel is through  "Composer".

Composer is a dependency manager software which manages the PHP project dependency on a fly. The project should have composer.json file where all the required dependencies are listed, Composer install them automatically.

To use composer in PHP projects, You have to download and install composer in your computer first. Here are the steps:

1-First download the composer

2-Now open the executable file to install it
What is Composer in PHP/Laravel? How to Install PHP Composer

3-Make sure to check developer mode as this will install the composer globally and you don’t have to add the composer path in environment variable to use it.
composer-php


4-Now you have to choose the command line PHP executable file.

installing-composer-php


5- If you are using xammp then click browse and navigate to the root path of your xammp installation and open the PHP folder where you will find a executable file named php.exe, Select it and click next

composer-in-php-laravel
composer-in-php-laravel


6- Now click next without checking proxy server as generally it is not needed (unless you are using some sort of VPN)

composer-in-php

7-Now click finish and you are done with the installation of composer.

Using Composer in PHP/Laravel:


Now we will see a little quick demo on using composer in laravel.

1-Installing any package with composer is just a game of one line, enter one command in command prompt hit enter and from here composer will do the rest of the magic.

2-There are two ways to install Laravel using composer

First way:

1- For installing laravel navigate to the folder where you want to install laravel using cmd.

2-We will use the following command to install laravel:  composer create-project laravel/laravel {directory} {version}

4-This command will simply clone the laravel from the GitHub repo directly to your PC.

5- So in my case I ran following command: Composer create-project laravel/laravel  laravel-practicles  "5.7.*"

6-I first navigate to my htdocs folder then I ran the above command.

7-This command installs the laravel in laravel-practicles folder.

Second way:

1-First, download the laravel installer using composer: composer global require laravel/installer

2-This command will install the laravel package globally in our local system

3-Now to create project for laravel again and again we can just ran following command: laravel new project-name

4-The above command will create a fresh laravel  directory in the specified folder

5-This method is fast and i personally like this.

As you know laravel has many dependencies but since we are using composer to install laravel, All the required dependencies will be automatically installed by composer.

This was the just glimpse of how powerful PHP composer is, I recommend you to use it in your projects when installing any external library as it will be life savior for you.

Let me know in comments if you have any questions/issues regarding composer in PHP, Thanks.


Sunday, November 18, 2018

November 18, 2018

Strategy Pattern (Design Patterns) in PHP


Aj is article me ham parhen gen Strategy Pattern ke bare me ke Design Patterns kia hoten hain? Strategy Pattern kia hay, Uske ilawa Php Design Patterns ke bare me kuch general concepts aur phir ham sikhen gen ke PHP me kis tarah ham is strategy pattern ka use krskte hain.
Strategy-Pattern-PHP

Tuesday, October 30, 2018

October 30, 2018

How to Create Simple CV Generator Using mPDF Library in PHP

In this article we will learn How to Develop a Simple CV Generator in PHP using mPDF library. We will also use CSS & JS framework bootstrap and vue.js in our project. So without any delay, let’s start

Intro:
We will develop a CV generator web app which allows user to generate a PDF CV after user enter his details i.e name, skills, experience bio and click generate button. You can checkout the scshot below:
How to Create Simple CV Generator Using mPDF Library in PHP