Create staging environment using GitLab

Prequisite: Please go through the steps to set up GitLab on the Production/live server before going through this tutorial. Steps to create a staging environment using GitLab branch 1. Create a new branch for your GitLab project as shown below 1 A. Go to your project page in GitLab and click the option to add New branch 1 B. Create a new branch named as dev 2. Create your staging site by copying the files and the necessary databases 3. Follow all the steps mentioned on the article Autodeployment using GitLab Webhooks on your staging sever with only the exception of Step 7 which needs to be modified slightly on the staging server. For the staging server that command would change to [crayon-59c7ebc37e7f3304943892/] Please note we are checking out only the dev branch on the staging server. So only your changes on the dev branch will be seen on this server. 4. Add the staging webhook.php file also to the list of webhooks on GitLab for Push events as shown below This completes setting up your...
Read More

Autodeployment using GitLab Webhooks

GitLab Webhooks GitLab provides various Webhooks to perform automated tasks after a certain event. For e.g. Push events Gitlab webhooks will work exactly similar to post-receive hook in GIT. Only thing is it needs a webpage (mostly on your server) which gets executed after a certain commit is made to the GitLab repository. This webpage can perform tasks like updating the local mirror repository and making the corresponding change in the files in your public_html folder. Read more about webhooks in GitLab Assuming you have a GitLab repository at: git@gitlab.com:username/some_project.git Steps to follow on your production/live server SSH to your production/live server Generate an SSH key for auto deployment to be used by the GitLab server [crayon-59c7ebc37ef55434636000/] Name of the key: gitlab_rsa_deploy, keep the passphrase blank Add the contents of the gitlab_rsa_deploy.pub key to Deyloy Keys section of your Project Settings and Enable it Create a config file in .ssh folder and add below contents to the file. Add your user key added to GitLab user key settings. [crayon-59c7ebc37ef5e269249676/] Create...
Read More

Types of GIT repositories

Three types of GIT repositories GIT working repository GIT bare repository GIT mirror repository GIT working repository This repository is the one which is on your local machine. This is the respositoy which you work on i.e. add, edit or delete your application files and commit your changes. This repository can be created using below 2 ways git init: Initialises an empty working repository. Necessary files are then added or created later. This command is mostly used when you are starting with a new application in which case the repository is empty when you begin. git clone: This command is used if you already have a working repository on your server, GitHub, GitLab, etc. This will create a Git repository on your local maching with working/application files already inside the repository. This repository has a .git folder with all the version related files inside this folder while your application files reside outside this folder. GIT bare repository This repository is generally created on your server mostly for...
Read More

How to connect to a remote GIT from Windows PC

Download and Install GIT Tool from below URL: https://msysgit.github.io/ While installing the tool keep all the default settings Create a folder named as projects for your site/application (maybe in your Documents folder) Open GIT GUI tool and generate a key from the Help menu The keys get created in your Users/USERNAME/.ssh folder Import both (public and private) keys to your server using CPanel Open GIT command line tool and navigate to the Documents folder (i.e. one folder above projects) Run the command: git clone ssh://USERNAME@IP_ADDRESS/home/USER/repositories/REPO_NAME   Now just make some changes to your code and commit the change using git commit The changes can be pushed to the remote server using below command git push origin master...
Read More

Set remote GIT on VPS / Dedicated server

It is possible to set Remote GIT on your own server provided your hosting provider allows to install GIT on the server. If your site/application is hosted on VPS or a dedicated server then it much easier to do so. Prerequisite to set remote GIT GIT should be installed on there server If you are on VPS or dedicated server then it is likely that GIT is already installed on the server. To check if GIT is installed or not SSH to your server and try below command. [crayon-59c7ebc37f5be930693974/] If GIT is installed then it will show the version of GIT. If not it will give an error message. If GIT is not installed then you first need to install GIT on your server. For this you may need root access to your server. If you do not have root access ask your hosting provider to install GIT for you. Once git is installed follow below steps on the server to set remote GIT Create a Directory SSH to your server (using...
Read More

Importing SSH key into keychain on Mac

Importing an SSH key to your keychain on Mac allows you to login without entering your passphrase each time. This helps if you are a developer and require to commit your changes to the server quite frequently. Here are the steps If you have a Cpanel on your server, login to your CPanel Generate an SSH Key (choose a suitable passphrase while generating the key and make a note of it) Once the SSH Key is generated, Authorise the key Download Private and Public keys and copy both the keys to your ~/.ssh directory Change permissions on both keys, Remove staff, everyone no access, Admin read write Open terminal and run: ssh-add -K ~/.ssh/KEY_NAME When prompted enter passphrase used while creating the key ...
Read More

How to remove a file/folder from GIT but keep it in the file system

Using the below commands will remove the file/folder from GIT but will also remove them from the local file system [crayon-59c7ebc37f878729654206/] So how can I remove this file/folder from the repo without deleting them in my local file system [crayon-59c7ebc37f880311483367/] So the conclusion is git rm removes a file from the working directory and the index and when you commit, the file is removed from the tree as well while git rm --cached removes the file from only the index and keeps it in your working copy....
Read More