Friday, September 3, 2021

Howto compare 2 GIT branch

 The benefits of GIT is being able to work in different branches from the master codebase. Commonly a new feature being developed would be published to a new branch for review before being merged to the master branch. Once it is merged to the master branch, the new branch would be removed from the remote site.

Before merge to the master branch, it is possible to compare between the 2 branches. This will allow a check on files changes and where are the code changes. Here, lets see how to retrieve the new branch from remote, then compare changes made. The git command format in general would be;

git option <arguments>


  • code base is in the branch master
  • remote name is origin
  • new remote branch is FEATURE
  • git version 1.8 and 2.19

Retrieve a remote branch

This section is more of a recap where the remote branch does not exist on your local machine. The option branch can use -b or -t depending on your needs. There is the example with -t where it creates the required branch locally and fetch its contents from remote.

git branch -t origin/FEATURE

git checkout FEATURE

View latest commit in the branch

git log

git log --oneline

Compare difference between branch

git diff master..FEATURE

View only the files that changed

git diff --name-status master..FEATURE

This describes use with TWO dots in the diff option. There is a THREE dots with the diff, but display results that compares the common between the 2 branches. More commonly, in cases that feature is already merged to master, it will produce no results.

Compare difference between commits

Displaying differences in commit between branches is ideal to identify developer notes in the commit between branches at level of commits.

git log master..FEATURE

There are many options to display log difference. Here is one example

git log --oneline --graph --decorate --abbrev-commit master..FEATURE

Compare difference in a file

When working to identify where a specific file has changed between two branches, just mention the relative path of the file

git diff master..FEATURE -- public/js/app.js

Compare with difftool

Here is an option to launch external editors to view the diff results. 

git difftool master..FEATURE

If required, a full directory diff can be done by adding the argument -d. This works fine on our linux systems, but on a GUI environment, the graphical code editors can be configured and activated with the argument -g.

Thats the basics to compare two branches using the diff and log options. Comparing existing branch or commits can be done with shorthand notations, which is much easier and I did not mention them here. This will help to ensure a smoother management of source codes.

Tuesday, July 20, 2021

Disable "your organization requires you to change your password" in Windows 10

 This might not be part of the open source, but its just a thing to blog.

Recently a windows 10 Home, login screen after successfully entering the PIN popup the message "your organization requires you to change your password" and forced users to change the pin before proceeding. Those who were not aware, changed it, but did not remember this new PIN the next time they needed to login.

I am trying out this method, but can't say it works as I have not done more test. Its just for my record


In Windows 10, press Win+r and type regedit

Scroll through Registry Editor, explorer like navigation as follow


Look for the item within that sub-folder named Policies\PINComplexity where it contain several value. Change the value named "Expiration". Double click and choose decimal. In Value data put in the number of days before the PIN expires. 

I can't say whats the correct value to disable, but for now I am using the Value data=600 (in decimal). Expecting the PIN to last 600 days. Maybe Windows 11 would be out by then.

Monday, July 12, 2021

KVM virtual machine on Centos 8 - Change name and Create snapshots

 Virtualisation provide a more efficient use of memory, disk and all CPU on a server. Separate servers can be managed within a single server. Centos 8 provide virtual machine (VM) management through KVM (kernel virtual machine).

 Each VM is given a domain name. Common practice before upgrading a server operating system, is to create a backup the current VM, or as its known here, a snapshot. Default format in use is qcow2, where tools for snapshot will work. Through Virtual Machine Manager and Cockpit, virtual machines can be created and managed. 

Centos 8 Cockpit view of VM administration

 Creating of virtual machines is not covered in here as its quite straight forward. Mostly it depends on the organisation practise and best practises.

  • Centos 8 is installed with virtual machine manager.
  • A virtual machine is already added with the name "Centos7_php"

 Let's work with an existing VM named "Centos7_php". This virtual machine is installed with the operating system Centos Linux 8 and all the other packages required as a PHP development server. This requires the VM to be shutdown (and there are no snapshots)

Display available running VM


virsh list

Shutdown VM

virsh shutdown {domain}
virsh shutdown Centos7_php

Rename VM

virsh domrename {domain} {new_name}

virsh domrename Centos7_php php_development

Startup VM

Note: The following will continue to use the initial VM name of Centos7_php.

virsh start {domain}

virsh start Centos7_php

Retrieve VM configuration

virsh dumpxml {domain}

List available snapshots for a domain

virsh snapshot-list --domain {domain}

Create a snapshot

Snapshots can be created while a VM is running. Best practise would be to stop the VM, where possible. The reason why double-quotes are used here, is that its common to have snapshot name with spaces. But no so for the domain name.
virsh snapshot-create-as --domain {domain} --name "{snapshot_name}"

View details of a snapshot with syntax:
virsh snapshot-info --domain {domain} --name "{snapshot_name}"

Example of creating a snapshot, then showing its details

virsh snapshot-create-as --domain Centos7_php \ 
  --name "2021July" --description "Snapshot initial stages"
virsh snapshot-list --domain Centos7_php
virsh snapshot-info --domain Centos7_php --name "2021July" 

Revert to a specific snapshot

Ensure the VM is shutdown before switching to a snapshot. Here is the syntax and an example.
virsh --snapshot-revert --domain {domain} --snapshotname "{snapshot_name}"

Example to switch to a snapshot known and initial.

virsh shutdown Centos7_php
virsh --snapshot-revert --domain Centos7_php \
     --snapshotname "2021July"
virsh start Centos7_php 

Delete a snapshot

Each snapshot takes up disk space, and these can be removed when not in use anymore.

virsh --snapshot-delete --domain {domain} --snapshotname "{snapshot_name}"

Example to delete a snapshot

virsh --snapshot-delete --domain Centos7_php --snapshotname "2021July" 

Saturday, July 3, 2021

Howto check Centos 7 and 8 common services

In Centos 7 and earlier, SysV manage Linux services. To list such services, 

config --list

Centos 7 and 8 uses Systemd to manage Linux services. The syntax for this command is

systemctl [OPTIONS...] COMMAND [UNIT...]

Centos 7 was a transition phase towards the newer Systemd, and it maintained a mix of service types.

Here are a list of common command to check Linux services.

List active systemd services


List all systemd services

systemctl -a

List only SysV services (centos 7 and older)

systemctl list-unit-files

List by service types

systemctl list-units --type service

systemctl list-units --type mount


LOAD   = Reflects whether the unit definition was properly loaded.

ACTIVE = The high-level unit activation state, i.e. generalization of SUB.

SUB    = The low-level unit activation state, values depend on unit type.

Check status of a service

systemctl status sshd.service

sudo systemctl status nfs-server.service

To stop or start or restart a service

sudo systemctl stop nfs-server.service

sudo systemctl start nfs-server.service

sudo systemctl restart nfs-server.service

To determine service is active or enabled the following will return 0 (active) and non zero (disabled)

systemctl is-active sshd

systemctl is-enabled sshd

systemctl is-active nfs-server

systemctl is-enabled nfs-server

To list a service and its dependencies;

 systemctl list-dependencies nfs-server

List services and their number of running task, CPU percentage, memory usage and I/O continuously


List services as above once

systemd-cgtop -n 1

To sort, use the following based on the column titles

systemd-cgtop -t 

systemd-cgtop -c

systemd-cgtop -m

systemd-cgtop -i

List services and their open ports

netstat -a

List services that use TCP and UDP and their open ports

netstat -tulpn

Display which user is used for a filename

fuser . -v

Display running service


Display running services in pretty formatting and enable F1-F10 commands.


Monday, June 28, 2021

Pagination within Laravel

One of the most common operations in Laravel involves the index.blade.php file. It displays a list of all the contents that an object retrieves from the database. In situations where there are thousand of rows of data, the view would best display it across many pages.

In Laravel, Pagination by default is compatible with Tailwind CSS framework and Bootstrap 4. When the number of rows are huge, its essential that the database column where the "whereby" clause is used, is index. 

Lets see 2 methods to apply pagination in a Laravel project using Bootstrap 4. 

Edit file App\Providers\AppServiceProvider.php

public function boot(){

Lets consider ArticleController that retrieves Article objects from the database through the function index(). This will display all the articles through a View called index.blade.php. For simplicity, only a total of 3 items will be displayed per page. 

Method 1: Using Paginate

Users will be able to view pagination with page numbers.

Pagination display

Edit app\Http\Controllers\ArticleController.php

public function index()
   $itemsPerPage = 3;
   $notes = Note::latest()->paginate($itemsPerPage);
   return view('notes.index', compact('notes'));

Edit resources\views\articles\index.blade.php and below the displayed date listing add the pagination.

{!! $notes->links() !!}

Additional functions available to use with Paginator

  • Number of items in current page $notes->count()
  • Current page number $notes->currentPage() 
  • Last page available $notes->lastPage()

Method 2: Using Cursor

Users will be able to view pagination with only the previous, and next navigation.

Cursor pagination

Edit app\Http\Controllers\ArticleController.php

public function index()
   $itemsPerPage = 3;
   $notes = Note::latest()->cursorPaginate($itemsPerPage);
   return view('notes.index', compact('notes'));

Edit resources\views\articles\index.blade.php and below the displayed date listing add the pagination.

{!! $notes->links() !!}

Additional functions available to use with Cursor

  • Number of items in current page, $notes->count()
  • Determine if cursor is on the first page, $notes->onFirstPage() 
  • Returns value of 1 if there are more pages to be split, $notes->hasMorePages()

Customise Pagination

This can be done by generating the required pagination files for customisation.

php artisan vendor:publish

Then select laravel-pagination and press enter. Find the files in the folder vendor/pagination in the project's view folder. Edit default.blade.php for a custom pagination layout. Here is an example of a customised Paginate.

Friday, May 28, 2021

How to clone a git branch

These notes are for Centos Linux version 7 (git 1.8) and 8 (git 2.7). 

Git is used as a repository to maintain source codes. Its advantage is in being able to manage source codes and files in a distributed way. This allow each one author to have the history and control of the source codes and files that are in their own access. 

A repository is commonly stored at a server and is accessed commonly through secure shell (SSH) or web (HTTP, HTTPS). Programmers, testers and others may clone (make a copy) of the repository OR a branch of the repository to their local machine.

Example of the command to clone by SSH where the username is git, the server URL is 

git clone

When a repository is created, it is common to have the default branch name "master". From there, source code for development or testing is created in a new branch. 
git branch listing

Example it can be name by functionality "customer-feature". From that branch, another new branch can even be created, for example "customer-view".

git checkout -b customer-feature
git checkout -b customer-view

To switch between branches, use the command checkout

git checkout customer-feature

Then this new branch can be added to the repository with the option "-u".

git push -u origin customer-feature

Further changes to the branch can be easily added to the repository with the command

git push origin customer-feature

Most of the commands listed here should require administration rights.


yum install git
dnf install git

Clone the whole repository

git clone

cd laraveljsonapi

Then list the branches in local and at remote server.

git branch -a

View activity at remote branch

git remote show origin

Clone a branch from repository

Start from a directory where the branch should be created.

git clone -b customer-feature

cd customer-feature

View log activity of that branch

git log

Thursday, March 11, 2021

Backup Postgresql Database

Here are the basic steps to backup and restore Postgresql database. At this point of writing, I am using Postgresql 10 and 11 on Centos Linux 8. 

In this article, backup database is inventory_system and restore of the backup is to another database that I will call cupboard.

Singles Database

Step 1: Login as postgres user

su - postgres


sudo su postgres -

Step 2: Dump the database content to a file using the tool pg_dump

pg_dump inventory_system >  inventory_system-20210312.bak

or when database is located at IP with port 5432

pg_dump -h -p 5432 inventory_system >  inventory_system-20210312.bak

Step 3: Create the new database

createdb cupboard

Step 4: Restore the database file with psql

psql cupboard <  inventory_system-20210312.bak

On MS Windows 10 prompt that is provided through Laragon, the postgres user login is required

pg_dump -U postgres cm2020_1 > test.bak

Schedule backup

Cron job is suitable to automate the backup process mentioned above. To schedule a cron job, use the command

crontab -e

Then save the following instruction to run at midnight of every Saturday

0 0 * * 6 pg_dump -U postgres inventory_system > ~/postgres/backups/inventory_system-20210312.bak

Save and exit from the text editor.

Refer to Cron activities in the file /var/log/cron

For automated backup, there is a good note with the scripts at Postgresql wiki.

Blog Archive