Thursday, 11 January 2024

Dynamic Routing Configuration – RIP, IGRP

 

Dynamic Routing Configuration – RIP, IGRP




















I think If you followed the previous posts that I published under IP configuration in CISCO Packet tracer software, this won't be a big task for yu to design and load the above network now.

Follow the steps below one by one so that you will be learning how to perform dynamic routing configuration without having doubts. Though the steps are almost similar to the previous post, I'll be mentioning the commands of CLI then and there as necessary.


Step1: Design the above network and load it in to Packet Tracer Simulator.

Note:   For R1 and R3 - Router 1841.            For R2 – router 2811
            Select R1 – S0 and R2 – S1 as DCE side for clocking inside the simulator.

Step2 :Name R1, R2 and R3 as Malabe, Metro and Matara.


Router(config)#hostname MALABE
Router(config)#hostname METRO
Router(config)#hostname MATARA

Step3 : Design a suitable IP plan for the above networks.

For simplicity, the IP plan is marked clearly in the above diagram it self making easy for you to understand. I have used subnetting in the very similar way that was used in the previouse post (STATIC ROUTING AND DEFAULT ROUTING CONFIGURATIONS)

Step4 : Configure the Serial and Ethernet interfaces of routers.

Step5: Assign clock rate as 64000 for the R1 serial 0 and R2 serial 1 interfaces.


For Router1
MALABE(config)#interface fastEthernet 0/0
MALABE(config-if)#ip address 192.168.10.1 255.255.255.0
MALABE(config-if)#no shutdown
MALABE(config-if)#exit

MALABE(config)#interface serial 0/0/0
MALABE(config-if)#ip address 10.0.0.1 255.0.0.0
MALABE(config-if)#clock rate 64000
MALABE(config-if)#no shutdown

MALABE(config-if)#exit

For Router2
MATARA(config)#interface fastEthernet 0/0
MATARA(config-if)#ip address 192.168.12.1 255.255.255.0
MATARA(config-if)#no shutdown
MATARA(config-if)#exit

MATARA(config)#interface serial 0/0/0
MATARA(config-if)#ip address 11.0.0.2 255.0.0.0
MATARA(config-if)#no shutdown
MATARA(config-if)#exit

For Router0
METRO(config)#interface fastEthernet 0/0
METRO(config-if)#ip address 192.168.11.1 255.255.255.0
METRO(config-if)#no shutdown
METRO(config-if)#exit

METRO(config)#interface serial 0/0/0
METRO(config-if)#ip address 10.0.0.2 255.0.0.0
METRO(config-if)#no shutdown

METRO(config-if)#exit
METRO(config)#interface serial 0/0/1
METRO(config-if)#ip address 11.0.0.1 255.0.0.0
METRO(config-if)#clock rate 64000
METRO(config-if)#no shutdown

METRO(config-if)#exit

Step6 : Configure the PC’s. (IP address, Subnet Mask and Default Gateway).











Configure the routers with RIP and IGRP to enable dynamic routing.

Dynamic routing could be done using Interior Gateway Protocols (IGP) and Exterior Gateway Protocols (EGP). We apply IGP for LANs and EGP for WANs.

IGRP, EIGRP, RIP and OSPF are some of these IGPs and BGP is an example for EGP.

First let’s see how to perform routing using RIP

Here for each router we have to use RIP and consider the directly connected network addresses of them to perform this routing.

MALABE(config)#router rip
MALABE(config-router)#network 192.168.10.0
MALABE(config-router)#network 10.0.0.0

METRO(config)#router rip
METRO(config-router)#network 10.0.0.0
METRO(config-router)#network 11.0.0.0
METRO(config-router)#network 192.168.11.0

MATARA(config)#router rip
MATARA(config-router)#network 192.168.12.0
MATARA(config-router)#network 11.0.0.0

Use ‘ping’ command to check the connectivity.

For PC0
PC>ipconfig

IP Address......................: 192.168.10.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.10.1

PC>ping 192.168.11.2

Pinging 192.168.11.2 with 32 bytes of data:

Reply from 192.168.11.2: bytes=32 time=94ms TTL=126
Reply from 192.168.11.2: bytes=32 time=94ms TTL=126
Reply from 192.168.11.2: bytes=32 time=79ms TTL=126
Reply from 192.168.11.2: bytes=32 time=73ms TTL=126

Ping statistics for 192.168.11.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 73ms, Maximum = 94ms, Average = 85ms

PC>ping 192.168.12.2

Pinging 192.168.12.2 with 32 bytes of data:

Reply from 192.168.12.2: bytes=32 time=111ms TTL=125
Reply from 192.168.12.2: bytes=32 time=109ms TTL=125
Reply from 192.168.12.2: bytes=32 time=125ms TTL=125
Reply from 192.168.12.2: bytes=32 time=110ms TTL=125

Ping statistics for 192.168.12.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 109ms, Maximum = 125ms, Average = 113ms

PC>


For PC1

PC>ipconfig

IP Address......................: 192.168.12.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.12.1

PC>ping 192.168.10.2

Pinging 192.168.10.2 with 32 bytes of data:

Reply from 192.168.10.2: bytes=32 time=125ms TTL=125
Reply from 192.168.10.2: bytes=32 time=125ms TTL=125
Reply from 192.168.10.2: bytes=32 time=125ms TTL=125
Reply from 192.168.10.2: bytes=32 time=125ms TTL=125

Ping statistics for 192.168.10.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 125ms, Maximum = 125ms, Average = 125ms

PC>ping 192.168.12.2

Pinging 192.168.12.2 with 32 bytes of data:

Reply from 192.168.12.2: bytes=32 time=0ms TTL=128
Reply from 192.168.12.2: bytes=32 time=15ms TTL=128
Reply from 192.168.12.2: bytes=32 time=0ms TTL=128
Reply from 192.168.12.2: bytes=32 time=15ms TTL=128

Ping statistics for 192.168.12.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 15ms, Average = 7ms


For PC2
PC>ipconfig

IP Address......................: 192.168.11.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.11.1

PC>ping 192.168.10.0

Pinging 192.168.10.0 with 32 bytes of data:

Reply from 10.0.0.1: bytes=32 time=63ms TTL=254
Reply from 10.0.0.1: bytes=32 time=63ms TTL=254
Reply from 10.0.0.1: bytes=32 time=63ms TTL=254
Reply from 10.0.0.1: bytes=32 time=62ms TTL=254

Ping statistics for 192.168.10.0:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 62ms, Maximum = 63ms, Average = 62ms

PC>ping 192.168.12.2

Pinging 192.168.12.2 with 32 bytes of data:

Reply from 192.168.12.2: bytes=32 time=93ms TTL=126
Reply from 192.168.12.2: bytes=32 time=94ms TTL=126
Reply from 192.168.12.2: bytes=32 time=94ms TTL=126
Reply from 192.168.12.2: bytes=32 time=94ms TTL=126

Ping statistics for 192.168.12.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 93ms, Maximum = 94ms, Average = 93ms

PC>


Now let’s see how to perform routing using EIGRP

EIGRP is also an Interior Gateway protocol which is applied to one autonomous system. So to apply it, first we should have the same Autonomous number for all the networks. Otherwise all PC in the Autonomous system cannot communicate.
How to apply?

Note:-do not use many protocols at the same time. If so, first remove all the previous routing commands and then use EIGRP (In this case…type…no router rip in each router)

MALABE(config)#router eigrp 200
MALABE(config-router)#network 192.168.10.0
MALABE(config-router)#network 10.0.0.0

METRO(config)#router eigrp 200
METRO(config-router)#network 10.0.0.0
METRO(config-router)#network 11.0.0.0
METRO(config-router)#network 192.168.11.0

MATARA(config)#router eigrp 200 
MATARA(config-router)#network 192.168.12.0
MATARA(config-router)#network 11.0.0.0

According to the methods shown above routing could be done statically or dynamically by using routing protocols (or even by default) to route different networks to communicate with each other.

Static Routing and Default Routing Configurations















Use the knowledge you gain from the previous posts of router configuration since this activity needs knowledge up to static routing and we are going to learn something called Default routing here something which is similar to static routing.

Step1 

Design the above network and load it in to Packet Tracer Simulator.
(Router 2811 has 1 Ethernet and 2 Serial interfaces.Select R1 – S0 and R2 – S1 as DCE side for clocking inside the simulator)


















For R1 and R2, use 1841 routers and add single serial port for each.


















Since R3 needs two serial ports, use 1841 router but add two serial ports as shown above.

Step2

Name R1, R2 and R3 as Malabe, Metro and Matara.

For R0 -->
Router(config)#hostname MALABE

For R1 -->
Router(config)#hostname METRO

For R2 -->
Router(config)#hostname MATARA

Step3

Design a suitable IP plan for the above networks.Note: Subnetting can be applied. (eg. 10.1.0.0 255.255.0.0)


Applying Subnetting

Assume that the given Network address is 192.168.10.0 It belongs to class C. Therefore cannot harm to the first three Bytes. We have to make 5 subnets (3 LANs and 2 WANs) we can go for creating 8 subnets using 3 bits from the host side of the given Network address (23)

It's easy if you write the host ID expanded in binary to represent the eight bits meanwhile e leaving the network ID part as it is because we are not suppose to change it.

The possible combinations are:-

 Sub net addresses |   possible IP addresses
192.168.10.0000 0000 Ã  192.168.10.0         192.168.10.0   X because it is the network address of subnet zero
                                                            192.168.10.1                                                                
                                                            192.168.10.2
                                                            192.168.10.31 X because it is the DB address of subnet zero

192.168.10.0010 0000 Ã  192.168.10.32       192.168.10.32 X because it is the network address of subnet 1
                                                            192.168.10.33                                                             
                                                            192.168.10.34
                                                            192.168.10.63 X because it is the DB address of subnet 1

192.168.10.0100 0000 Ã  192.168.10.64       192.168.10.64 X because it is the network address of subnet 2
                                                            192.168.10.65                                                             
                                                            192.168.10.66
                                                            192.168.10.95 X because it is the DB address of subnet 2

192.168.10.0110 0000 Ã  192.168.10.96       192.168.10.96 X because it is the DB address of subnet 3
                                                            192.168.10.97                                                             
                                                            192.168.10.98
                                                            192.168.10.127 X because it is the DB address of subnet 3
192.168.10.1000 0000 Ã  192.168.10.128     192.168.10.128 X because it is the network address of subnet 4
                                                            192.168.10.129                                                          
                                                            192.168.10.130
                                                            192.168.10.159 X because it is the DB address of subnet 4

192.168.10.1010 0000 Ã  192.168.10.160     192.168.10.160 X because it is the network address of subnet 5
                                                            192.168.10.161                                                          
                                                            192.168.10.162
                                                            192.168.10.191 X because it is the DB address of subnet 5

192.168.10.1100 0000 Ã  192.168.10.192     192.168.10.192 X because it is the network address of subnet 6
                                                            192.168.10.193                                                          
                                                            192.168.10.194
                                                            192.168.10.223 X because it is the DB address of subnet 6

192.168.10.1100 0000 Ã  192.168.10.224     192.168.10.224 X because it is the network address of subnet 7
                                                            192.168.10.225                                                          
                                                            192.168.10.226
Note that the IP addresses within the above shown purple colored addresses for each subnet could be used as valid IP addresses for each sub network’s hosts. Make sure to omit the network address and direct broadcast (DB) address in each sub network. Since we only need two IP addresses for each of our five networks, simply the first two IPs could be used.

Step4 

Configure the Serial and Ethernet interfaces of routers and assign clock rate as 64000 for the R1 serial 0 and R2 serial 1 interfaces.

For Router1
MALABE(config)#interface fastEthernet 0/0
MALABE(config-if)#ip address 192.168.10.1 255.255.255.224
MALABE(config-if)#no shutdown

MALABE(config-if)#exit
MALABE(config)#interface serial 0/0/0
MALABE(config-if)#ip address 192.168.10.97 255.255.255.224
MALABE(config-if)#clock rate 64000

MALABE(config-if)#no shutdown
MALABE(config-if)#exit

For Router2
MATARA(config)#interface fastEthernet 0/0
MATARA(config-if)#ip address 192.168.10.65 255.255.255.224
MATARA(config-if)#no shutdown

MATARA(config-if)#exit
MATARA(config)#interface serial 0/0/0
MATARA(config-if)#ip address 192.168.10.130 255.255.255.224
MATARA(config-if)#no shutdown
MATARA(config-if)#exit

For Router3
METRO(config)#interface fastEthernet 0/0
METRO(config-if)#ip address 192.168.10.33 255.255.255.224
METRO(config-if)#no shutdown

METRO(config-if)#exit
METRO(config)#interface serial 0/0/0
METRO(config-if)#ip address 192.168.10.98 255.255.255.224
METRO(config-if)#no shutdown

METRO(config-if)#exit
METRO(config)#interface serial 0/0/1
METRO(config-if)#ip address 192.168.10.129 255.255.255.224
METRO(config-if)#clock rate 64000
METRO(config-if)#no shutdown

METRO(config-if)#exit




Step5

Configure the PC’s. (IP address, Subnet Mask and Default Gateway)


Step6

Use ‘ping’ command to check the connectivity.

IP Address......................: 192.168.10.2
Subnet Mask.....................: 255.255.255.224
Default Gateway.................: 192.168.10.1

PC>ping 192.168.10.1

Pinging 192.168.10.1 with 32 bytes of data:

Reply from 192.168.10.1: bytes=32 time=63ms TTL=255
Reply from 192.168.10.1: bytes=32 time=32ms TTL=255
Reply from 192.168.10.1: bytes=32 time=32ms TTL=255
Reply from 192.168.10.1: bytes=32 time=31ms TTL=255

Ping statistics for 192.168.10.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 31ms, Maximum = 63ms, Average = 39ms

PC>ping 192.168.10.34

Pinging 192.168.10.34 with 32 bytes of data:

Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.

Ping statistics for 192.168.10.34:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

PC>ping 192.168.10.66

Pinging 192.168.10.66 with 32 bytes of data:

Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.

Ping statistics for 192.168.10.66:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

PC>

The above ping commands of PC0 summarizes that still the data exchange could be done successfully within Local Networks only. Networks still cannot identify their remote networks successfully. So we need to route to perform that task.

Step7 

Assign Static Routing to all the routers and check the connectivity.

Static routing is done by the administrator to make the remote networks of each network to identify and exchange data when the remote network addresses and subnet masks are known.


Assigning Default Routing to necessary routers.

Default routing is kind of similar to static routing but this is done when the network administrator doesn’t know the exact network addresses and subnet masks of remotely situated networks.

Note: - If we need to perform default routing to the same networks that we have already done static routing, then first we need to remove the static routing commands from them and then assign default routing commands.

To remove all the static routings use the below shown commands for each.

MALABE(config)#no ip route 192.168.10.64 255.255.255.0 192.168.10.98
MALABE(config)# no ip route 192.168.10.32 255.255.255.0 192.168.10.98

METRO(config)# no ip route 192.168.10.0 255.255.255.0 192.168.10.97
METRO(config)# no ip route 192.168.10.64 255.255.255.0 192.168.10.130

MATARA(config)#no ip route 192.168.10.0 255.255.255.0 192.168.10.129
MATARA(config)# noip route 192.168.10.32 255.255.255.0 192.168.10.129

How to set default routing…

MALABE(config)# ip route 0.0.0.0 0.0.0.0 192.168.10.98
METRO(config)# ip route 0.0.0.0 0.0.0.0 192.168.10.97
MATARA(config)# ip route 0.0.0.0 0.0.0.0 192.168.10.129

Note :- Since we don’t know the destination Network addresses and subnet masks, we simply assign them as 0.0.0.0 but the default gateway, what we already should know should be assigned as it is.

Final Step

Check the connectivity again.
PC>ipconfig

IP Address......................: 192.168.10.2
Subnet Mask.....................: 255.255.255.224
Default Gateway.................: 192.168.10.1

PC>ping 192.168.10.1

Pinging 192.168.10.1 with 32 bytes of data:

Reply from 192.168.10.1: bytes=32 time=31ms TTL=255
Reply from 192.168.10.1: bytes=32 time=31ms TTL=255
Reply from 192.168.10.1: bytes=32 time=31ms TTL=255
Reply from 192.168.10.1: bytes=32 time=31ms TTL=255

Ping statistics for 192.168.10.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 31ms, Maximum = 31ms, Average = 31ms
PC>ping 192.168.10.34

Pinging 192.168.10.34 with 32 bytes of data:

Reply from 192.168.10.34: bytes=32 time=109ms TTL=124
Reply from 192.168.10.34: bytes=32 time=125ms TTL=124
Reply from 192.168.10.34: bytes=32 time=125ms TTL=124
Reply from 192.168.10.34: bytes=32 time=125ms TTL=124

Ping statistics for 192.168.10.34:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 109ms, Maximum = 125ms, Average = 121ms

PC>ping 192.168.10.66

Pinging 192.168.10.66 with 32 bytes of data:

Reply from 192.168.10.66: bytes=32 time=125ms TTL=125
Reply from 192.168.10.66: bytes=32 time=125ms TTL=125
Reply from 192.168.10.66: bytes=32 time=109ms TTL=125
Reply from 192.168.10.66: bytes=32 time=125ms TTL=125

Ping statistics for 192.168.10.66:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 109ms, Maximum = 125ms, Average = 121ms

PC>

Now the data exchange throughout the network is done successfully.

Do not forget to copy the running-config files to the startup configuration files as shown below. This makes the running-configuration information (that are volatile and lost when the router is switched off). To non-volatile memory in NVRAM.

MALABE#copy running-config  startup-config
METRO#copy running-config startup-config
MATARA#copy running-config startup-config

Tuesday, 2 January 2024

How to Use Git Version Control System in Linux

 Version Control (revision control or source control) is a way of recording changes to a file or collection of files over time so that you can recall specific versions later. A version control system (or VCS in short) is a tool that records changes to files on a filesystem.

There are many version control systems out there, but Git is currently the most popular and frequently used, especially for source code management. Version control can actually be used for nearly any type of file on a computer, not only source code.

Version control systems/tools offer several features that allow individuals or a group of people to:

  • create versions of a project.
  • track changes accurately and resolve conflicts.
  • merge changes into a common version.
  • rollback and undo changes to selected files or an entire project.
  • access historical versions of a project to compare changes over time.
  • see who last modified something that might be causing a problem.
  • create a secure offsite backup of a project.
  • use multiple machines to work on a single project and so much more.

A project under a version control system such as Git will have mainly three sections, namely:

  • a repository: a database for recording the state of or changes to your project files. It contains all of the necessary Git metadata and objects for the new project. Note that this is normally what is copied when you clone a repository from another computer on a network or remote server.
  • a working directory or area: stores a copy of the project files which you can work on (make additions, deletions and other modification actions).
  • a staging area: a file (known as index under Git) within the Git directory, that stores information about changes, that you are ready to commit (save the state of a file or set of files) to the repository.

There are two main types of VCSs, with the main difference being the number of repositories:

  • Centralized Version Control Systems (CVCSs): here each project team member gets their own local working directory, however, they commit changes to just a single central repository.
  • Distributed Version Control Systems (DVCSs): under this, each project team member gets their own local working directory and Git directory where they can make commits. After an individual makes a commit locally, other team members can’t access the changes until he/she pushes them to the central repository. Git is an example of a DVCS.

In addition, a Git repository can be bare (repository that doesn’t have a working directory) or non-bare (one with a working directory). Shared (or public or central) repositories should always be bare – all Github repositories are bare.

Learn Version Control with Git

Git is a free and open source, fast, powerful, distributed, easy to use, and popular version control system that is very efficient with large projects, and has a remarkable branching and merging system. It is designed to handle data more like a series of snapshots of a mini filesystem, which is stored in a Git directory.

The workflow under Git is very simple: you make modifications to files in your working directory, then selectively add just those files that have changed, to the staging area, to be part of your next commit.

Once you are ready, you do a commit, which takes the files from staging area and saves that snapshot permanently to the Git directory.

To install Git in Linux, use the appropriate command for your distribution of choice:

$ sudo apt install git   [On Debian/Ubuntu]
$ sudo yum install git   [On CentOS/RHEL]

After installing Git, it is recommended that you tell Git who you are by providing your full name and email address, as follows:

$ git config --global user.name “Aaron Kili”
$ git config --global user.email “aaronkilik@gmail.com”

To check your Git settings, use the following command.

$ git config --list 
View Git Settings
View Git Settings

Creates a New Git Repository

Shared repositories or centralized workflows are very common and that is what we will demonstrate here. For example, we assume that you have been tasked to setup a remote central repository for system administrators/programmers from various departments in your organization, to work on a project called bashscripts, which will be stored under /projects/scritpts/ on the server.

SSH into the remote server and create the necessary directory, create a group called sysadmins (add all project team members to this group e.g user admin), and set the appropriate permissions on this directory.

# mkdir-p /projects/scripts/
# groupadd sysadmins
# usermod -aG sysadmins admin
# chown :sysadmins -R /projects/scripts/
# chmod 770 -R /projects/scripts/

Then initialize a bare project repository.

# git init --bare /projects/scripts/bashscripts
Initialize Git Shared Repository
Initialize Git Shared Repository

At this point, you have successfully initialized a bare Git directory which is the central storage facility for the project. Try to do a listing of the directory to see all the files and directories in there:

# ls -la /projects/scripts/bashscripts/
List Git Shared Repository
List Git Shared Repository

Clone a Git Repository

Now clone the remote shared Git repository to your local computer via SSH (you can also clone via HTTP/HTTPS if you have a web server installed and appropriately configured, as is the case with most public repositories on Github), for example:

$ git clone ssh://admin@remote_server_ip:/projects/scripts/bashscripts 

To clone it to a specific directory (~/bin/bashscripts), use the command below.

$ git clone ssh://admin@remote_server_ip:/projects/scripts/bashscripts ~/bin/bashscripts
Clone Shared Git Repository to Local
Clone Shared Git Repository to Local

You now have a local instance of the project in a non-bare repository (with a working directory), you can create the initial structure of the project (i.e add a README.md file, sub-directories for different categories of scripts e.g recon to store reconnaissance scripts, sysadmin ro store sysadmin scripts etc.):

$ cd ~/bin/bashscripts/
$ ls -la
Create Git Project Structure
Create Git Project Structure

Check a Git Status Summary

To display the status of your working directory, use the status command which will shows you any changes you have made; which files are not being tracked by Git; those changes that have been staged and so on.

$ git status 
Check Git Status
Check Git Status

Git Stage Changes and Commit

Next, stage all the changes using the add command with the -A switch and do the initial commit. The -a flag instructs the command to automatically stage files that have been modified, and -m is used to specify a commit message:

$ git add -A
$ git commit -a -m "Initial Commit"
Do Git Commit
Do Git Commit

Publish Local Commits to Remote Git Repository

As the project team lead, now that you have created the project structure, you can publish the changes to the central repository using the push command as shown.

$ git push origin master
Push Commit to Centrol Git Repository
Push Commit to Centrol Git Repository

Right now, your local git repository should be up-to-date with the project central repository (origin), you can confirm this by running the status command once more.

$ git status
Check Git Status
Check Git Status

You can also inform you colleagues to start working on the project by cloning the repository to their local computers.

Create a New Git Branch

Branching allows you to work on a feature of your project or fix issues quickly without touching the codebase (master branch). To create a new branch and then switch to it, use the branch and checkout commands respectively.

$ git branch latest
$ git checkout latest

Alternatively, you can create a new branch and switch to it in one step using the checkout command with the -b flag.

$ git checkout -b latest

You can also create a new branch based on another branch, for instance.

$ git checkout -b latest master

To check which branch you are in, use branch command (an asterisk character indicates the active branch):

$ git branch
Check Active Branch
Check Active Branch

After creating and switching to the new branch, make some changes under it and do some commits.

$ vim sysadmin/topprocs.sh
$ git status
$ git commit add  sysadmin/topprocs.sh
$ git commit -a -m 'modified topprocs.sh'

Merge Changes From One Branch to Another

To merge the changes under the branch test into the master branch, switch to the master branch and do the merge.

$ git checkout master 
$ git merge test 
Merge Test Branch into Master
Merge Test Branch into Master

If you no longer need a particular branch, you can delete it using the -d switch.

$ git branch -d test

Download Changes From Remote Central Repository

Assuming your team members have pushed changes to the central project repository, you can download any changes to your local instance of the project using the pull command.

$ git pull origin
OR
$ git pull origin master	#if you have switched to another branch
Pull Changes from Central Repository
Pull Changes from Central Repository

Inspect Git Repository and Perform Comparisons

In this last section, we will cover some useful Git features that keep track of all activities that happened in your repository, thus enabling you to view the project history.

The first feature is Git log, which displays commit logs:

$ git log
View Git Commit Logs
View Git Commit Logs

Another important feature is the show command which displays various types of objects (such as commits, tags, trees etc..):

$ git show
Git Show Objects
Git Show Objects

The third vital feature you need to know is the diff command, used to compare or show difference between branches, display changes between the working directory and the index, changes between two files on disk and so much more.

For instance to show the difference between the master and latest branch, you can run the following command.

$ git diff master latest
Show Difference Between Branches
Show Difference Between Branches

Summary

Git allows a team of people to work together using the same file(s), while recording changes to the file(s) over time so that they can recall specific versions later.

This way, you can use Git for managing source code, configuration files or any file stored on a computer. You may want to refer to the Git Online Documentation for further documentation.

How to Install Git on CentOS 8

 Version Control System tool plays a vital role in today’s modern Software development. Version control is a software that helps a group of software developers work together and manage the history of the work. It does not overwrite other’s changes, therefore you can keep track of every change, revert the file or a project to its previous state.

The version control tool helps you to recover the lost file very easily. If a mistake is made by anyone from the team, one can look back and compare the earlier version of the file and fix the mistake or any conflict.

Git is one of the most popular decentralized version control tools used by developers to coordinate the work amongst them. It was designed by Linus Torvalds ( the creator of Linux Kernel.) in the year 2005.

Git offers features like data assurance, workflows, create branches, revert to the previous stage, incredible speed, keep track of your code changes, view logs, and many more. It allows you to perform your work in offline mode and when ready, you need the internet connection to publish the changes and take the latest changes.

In this tutorial, we will explain to you how to install Git on a CentOS 8 server using yum and source code. Each installation has its own benefits, the choice is up to you.

For example, users who want to Perpetuate Git update will use the yum method and those who need features by a particular version of Git will use the source code method.

Important: You must have a CentOS 8 server installed and configured with a sudo user with root privileges. If you don’t have one, you can create a sudo account

Installing Git with Yum on CentOS 8

One of the simplest and easiest ways to install Git is with a yum package manager, but the available version may be older than the newest version available. If you want to install the newest release of Git, consider compiling it from source (instructions for compiling Git from the source given further down below).

$ sudo yum install git

Once installed git, you can verify the version of installed Git using the following command.

$ git --version

git version 2.18.1

Installing Git from Source Code

If you want to feature by a specific version of Git or need flexibility in installation then one of the best methods is to gather the software Git from Source. However, it will not manage and update Git installation through the yum package manager but will allow you to install the latest version of Git and customize the build options. This method is a bit lengthy process.

Before we move forward with the installation, you will need the following necessary tools to build the binary from the source.

$ sudo yum groupinstall "Development Tools"
$ sudo yum install wget unzip gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel libcurl-devel expat-devel

Once the tools are installed successfully, open any browser and visit Gits project’s mirror on GitHub Release. The one at the top is the latest version of Git, but it may vary at your end. Now, look at the version you require then right-click the source code (tar.gz) and copy the link to download using following wget command as shown.

$ sudo wget https://github.com/git/git/archive/v2.23.0.tar.gz -O git.tar.gz

Once the download is completed unzip the source package using tar command, now move into the directory.

$ sudo tar -xf git.tar.gz
$ cd git-*

Now install and build Git from source using the following command.

$ sudo make prefix=/usr/local all install

Once compilation finishes, you can type the following command to verify the Git Version installation.

$ git --version

git version 2.23.0

Configuring Git

Now git is installed on the CentOS machine successfully, now you will need to set up your personal info which will be used when you commit any changes to your code.

$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@yourdomain.com"

To verify that the above settings were added successfully, you can list all of the configuration settings that have been added by typing.

$ git config --list

user.name=Your Name
user.email=youremail@yourdomain.com

The above settings are stored in the global configuration ~/.gitconfig file. To make any additional changes to this file, use git config command or edit the file manually.