📌 Choosing Between AWS Load Balancers: ALB vs. NLB – Features, Use Cases and Technical Considerations📌
Choosing between AWS Application Load Balancer (ALB) and Network Load Balancer (NLB) depends on the specific requirements of your application's architecture, traffic patterns, and the protocols used. Both types of load balancers serve to distribute traffic across multiple targets, but they operate at different layers of the OSI model and offer different features. Here's a detailed comparison and an explanation of how each works:
✅ AWS Application Load Balancer (ALB)
Layer 7 Load Balancing: ALB operates at the OSI model's application layer (Layer 7). It can make routing decisions based on the content of the HTTP/HTTPS headers, URL paths, query strings, and more.
Features:
✔️ Content-Based Routing: ALB allows you to route traffic based on request content, making it ideal for modern application architectures, including microservices and container-based applications.
✔️ Host and Path-Based Routing: You can route traffic based on the domain name (host) or the URL path specified in the request.
✔️ Support for HTTP/2 and WebSocket: It supports advanced web protocols, which are beneficial for improving performance and real-time communication.
✔️ Integration with AWS Services: ALB integrates well with other AWS services, such as ECS (Elastic Container Service), EKS (Elastic Kubernetes Service), and AWS WAF (Web Application Firewall).
✅ AWS Network Load Balancer (NLB)
Layer 4 Load Balancing: NLB operates at the transport layer (Layer 4). It routes traffic based on IP protocol data, such as TCP port and IP address.
Features:
✔️ High Performance and Low Latency: NLB is optimized to handle millions of requests per second while maintaining low latencies.
✔️ Static IP or Elastic IP: Unlike ALB, NLB allows the assignment of a static IP per Availability Zone or the use of Elastic IP addresses.
✔️ Direct TCP and UDP Traffic Routing: Supports routing of TCP and UDP traffic, making it suitable for applications that require direct connection to the load balancer.
Choosing Between ALB and NLB
✔️ Protocol and Routing Requirements: If your application requires complex routing based on the content of the HTTP/HTTPS headers or needs WebSocket support, choose ALB. If your application primarily uses TCP or UDP and benefits from low latency and high throughput, go with NLB.
✔️ Performance Considerations: For ultra-high performance and low latency requirements, NLB is typically more suitable because of its ability to handle volatile high traffic patterns and its operational efficiency at the TCP level.
✔️ IP Address Needs: If having a static IP is crucial for your application deployment, NLB would be the better choice.
✔️ Integration and Features: Consider the additional features like WAF integration or the need for detailed routing rules, which might lean towards choosing ALB.
Monday, 6 May 2024
Choosing Between AWS Load Balancers: ALB vs. NLB
Friday, 18 February 2022
SonarQube installation on Ubuntu 20.04
1) Update System
sudo apt-get update && sudo apt-get upgrade -y
2) Install open-jdk
sudo apt-get install openjdk-11-jdk -y
cd /opt
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.6.zip
4) Extract SonarQube software
sudo unzip sonarqube-7.6.zip
sudo mv sonarqube-7.6 sonarqube
5) Please change permissions ( Update user as per requirement )
6) Start Sonar
cd /opt/sonarqube/bin/linux-x86-64
./sonar.sh start
You should able to access SonarQube over 9000 port now. By default admin/admin will be credentials for SonarQube.
If you are using VM or Vagrant please enable port forwarding.
Create sonar service file
sudo vi /etc/systemd/system/sonarqube.service
Add below content to above file. If you want to change user to run sonarqube process please update User and Group.
[Unit]
Description=SonarQube service
After=syslog.target network.target
[Service]
Type=simple
User=vagrant
Group=vagrant
PermissionsStartOnly=true
ExecStart=/bin/nohup java -Xms32m -Xmx32m -Djava.net.preferIPv4Stack=true -jar /opt/sonarqube/lib/sonar-application-7.6.jar
StandardOutput=syslog
LimitNOFILE=65536
LimitNPROC=8192
TimeoutStartSec=5
Restart=always
[Install]
WantedBy=multi-user.target
8) Start and Enable Sonar Service
sudo systemctl start sonarqube
sudo systemctl enable sonarqube
9) Check SonarQube status to ensure it is working as expected.
sudo systemctl status sonarqube
Jenkins installation on Ubuntu 20.04
1) Update System
sudo apt-get update && sudo apt-get upgrade -y
2) Install open-jdk
sudo apt-get install openjdk-11-jdk -y
3) Add Jenkins key.
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
6) Once Installation of Jenkins is completed start jenkins service.
sudo systemctl start jenkins
7) Enable Jenkins service to be restart on system reboot
sudo systemctl enable jenkins
8) By Default Jenkins will run and accessible over 8080 port. We need to open port to access in our browser if we are using Jenkins on Virtual Environment.
i) If you are using Vagrant please add below line to Vagrantfile and restart vm.
config.vm.network "forwarded_port", guest: 8080, host: 8080
ii) If you are using Oracle VirtualBox please follow below steps to open 8080 port
Right Click on VM and go to settings.
10) You need to copy the password from /var/lib/jenkins/secrets/initialAdminPassword to text box and click on continue.
Apache Tomcat 9 Installation on Ubuntu 20.04
1) Update System
sudo apt-get update && sudo apt-get upgrade -y
2) Install open-jdk
sudo apt-get install openjdk-11-jdk -y
3) Download Apache Tomcat and extract tomcat to your Linux Machine
cd /opt/
sudo wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.tar.gz
sudo tar -zxvf apache-tomcat-9.0.50.tar.gz
sudo mv apache-tomcat-9.0.50 tomcat
sudo chmod -R 777 tomcat
# Update vagrant user as per your requirement
sudo chown -R vagrant:vagrant tomcat
4) Configure Apache Tomcat 9 as system service.
Open tomcat service file sudo vi /etc/systemd/system/tomcat.service
Add below content.
[Unit]
Description=Tomcat 9
After=network.target
[Service]
Type=forking
# Update users as per target machine
User=vagrant
Group=vagrant
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
5) Start tomcat service
sudo systemctl start tomcat
5) Check tomcat service
sudo systemctl status tomcat
6) Enable tomcat service
sudo systemctl enable tomcat
Monday, 20 December 2021
Jenkins cannot delete root-owned files/folders in jenkins-owned directories
In this post we will discuss abut most frequent issues faced in Jenkins build.
When you try to use docker image to run your jobs you may end up in creating some file which are created by root user ( from Docker image ). In this case from next build onwards we will see some issues to clean old workspace. Even if you try to use cleanUP workspace plugin you will end up with permission issues.
To avoid this issue please follow below steps
1) Install acl package based on your distribution.
apt-get install aclapt-get install acl
Alpineapk add aclpacman -S aclapt-get install aclyum install acldnf install acl2) Follow below steps to clean workspace and apply acl on workspace folder. After this change you will see any file or folder which is created in workspace folder will have complete ownership of jenkins user. $ rm -rf workspace # to avoid any inconsistencies in existing files
$ mkdir workspace
$ sudo setfacl -dm 'u:<your_jenkins_user_name>:rwx' workspaceSaturday, 9 October 2021
Linux Technical Interview Questions
In some questions I am encouraging to search online because it will help you practice for
searching more complicated questions in the future
(Good Luck)
1. When you login you get “$” prompt, what is the prompt for root?
#
2. Explain the difference between grep and egrep?
Search online
3. What is the port # for DNS, NTP and NFS?
53,123 and 111/2049
4. What is the configuration file name of DNS and where is it
located?
/etc/named.conf
5. How many new directories will be created after running the
following command
mkdir {a..c}{1..3}
9
6. Your PC is configured with a DNS server address but not the
default gateway. Can the PC access internet?
No
7. What is the difference between IP and Gateway?
Search online
8. Can you assign one static IP to 2 computers, if not then why?
No because it will create IP conflict
9. How to change IPs address to static?
ifconfig x.x.x.x
10. You are trying to ping a server by hostname and you get an error
message, “ping: unknown host …”. What could be the reason and
how to solve the problem so you can ping it by hostname?
Check for /etc/hosts or DNS to see if it has hostname to IP entry
11. Explain the difference between relative and absolute path?
Absolute path starts from / where relative path is your current
directory
12. List 3 different methods of adding user?
Search online
13. What is the command to change file/directory ownership and group?
chown and chgrp
14. List any 3 type of filesystem?
ext4,NTFS and FAT
15. When you login you get a message on the screen. What is the name
of that file and where is it located?
/etc/motd
16. What is /bin directory used for?
Search online
17. What are the different types of DNS Server
Master and secondary
18. How to change a user password?
passwd username
19. What is the version of Redhat Linux you have experience with?
7.4
20. List any 4 linux distributions?
Redhat, CentOS, Ubuntu and SUSE
21. How to logoff from the system?
exit
22. Give any 3 examples of operating systems?
Windows, Linux and MAC
23. How to create a directory?
mkdir
24. Where are the zone files located for DNS service?
/var/named/zonefiles
25. How to check kernel version?
uname –a
26. Which directory has all the configuration files?
/etc
27. How to become root user from a regular user?
su –
28. How many mega bytes in 1 giga bytes?
Search online
29. What is the purpose of having different network ports?
So the communication of each application goes through a dedicated
port
30. How to display first column of a file?
cat filename | awk ‘{print $1}’
31. What is the name of DNS rpm package?
bind
32. What is the difference between nslookup and dig commands?
Search online
33. How to check your user id and group id?
id
34. How to check a file’s permission?
ls –l
35. What is the difference between “kill” and “kill -9” command?
Search online
36. What is subnet?
Search online
37. You are troubleshooting an issue with Redhat support and they
have asked you to send the contents of /etc directory. How and
which method you will use to transfer the contents?
tar (compress) the entire /etc directory and ftp
38. What is root home directory?
/root
39. What is rsyslogd deamon and its purpose?
Search online
40. Your company has terminated a server administrator. What is first
thing as an administrator you should do to enhance the security?
Change root password
41. How to check the computer name or host name in Linux?
hostname
42. Which permission allows a user to run an executable with the
permissions of the owner of that file?
First 3 bits should have x
43. What is the command to untar a tarred file?
untar
44. What is /proc directory used for?
Search online
45. What is the purpose of nsswitch.conf file
It tells the system where to go to resolve hostnames
46. List 3 basic commands to navigate the filesystem?
cd, pwd and ls
47. Which service/daemon should be running on the server that allows
you to connect remotely?
sshd
48. What is the purpose of firewall?
Search online
49. List any 3 IT components?
Hardware, OS and Applications
50. Which directory has all the commands we use, e.g. ls, cd etc.?
/usr/bin or /bin
51. What is the difference between memory, virtual memory and cache?
Search online
52. Which of the following is correct?
a. Hardware Operating System Users
b. Operating System Users Hardware
c. Database Hardware Users
53. Which of the following is a communication command?
o grep
o mail
o touch
o cd
54. How to rename a file or directory?
mv
55. How to change a hostname in Linux?
Search online
56. How to check network interfaces in Linux?
ifconfig
57. Why is “tail –f logfilename” command used most often and what
does it do?
It will output all incoming logs in real time
58. What type of hardware have you worked on?
You should get yourself familiar with Dell, HP and UCS hardware
by going online and check the vendor websites
59. How to sort a file in reverse order?
cat filename | sort –r
60. What is the name of operating system that runs Unix?
Solaris, HP-UX etc.
61. List all byte sizes from smallest to largest?
Search online
62. How to check the total number of partition in Linux?
fdisk -l
63. How to access a linux system from a linux system?
ssh
64. Explain the procedure of bonding 2 NICs or interfaces together?
Search online
65. What is the exact command syntax to list the 5th column of a file
and cut the first 3 letters?
cat filename | awk ‘{print $5}’ | cut –c1-3
66. What is /etc/hosts file used for?
To resolve hostnames with IP address
67. List any 3 options of ‘df’ command and what they are used for?
Search online
68. What is the command to change file/directory permissions?
chmod
69. What is the purpose of pipe (|)?
To combine multiple commands
70. What is /etc directory used for?
For configuration files
71. Which command is used to list files in a directory?
ls –l
72. There is a command which gives you information about other
commands, please explain that command and what is it used for?
man
73. How to delete a file and a directory?
rm filename and rmdir dirname
74. What is the difference between “tail” and “tail -10”?
None
75. List 4 commands to display or read a file contents?
cat, more, less, vi
76. Which command is used to read the top 5 lines of a file?
head -5 filename
77. What are the different commands or methods to write to a file?
echo > filename and vi filename
78. What is swap space and how to check swap space?
Search online
79. What is inode and how to find an inode of a file?
Search online
80. Which file to edit for kernel tuning?
Search online
81. What is the latest version of Redhat?
Search online
82. Name the command to find specific word from a file?
grep word filename
83. You have scheduled a job using crontab but it does not run at the
time you specified, what could be the reason and how would you
troubleshoot?
Check your system time
Check your crontab entry
Check /var/log/messages
84. How to check system hardware information?
dmidecode
85. How to check network interface MAC address?
ifconfig
86. If I don’t want others to read my file1, how to do that?
Remove r from the last 3 bits of file permission
87. What is the purpose of “uniq” and “sed” command?
Search online
88. Which command is used to list the contents of a directory in the
most recent time and in reverse order, meaning the most updated
file should be listed on the bottom?
ls –ltr
89. What is the difference between tar, gzip and gunzip?
Search online
90. What are the different ways to install and OS?
DVD, DVD iso and network boot
91. How to view difference between two files?
diff file1 and file2
92. You noticed that one of the Linux servers has no disk space left,
how would you troubleshoot that issue?
If running LVM then add more disk and extend LVM
If not running LVM then add more disk, create a new partition and
link the new partition to an existing filesystem
93. How to check Redhat version release?
uname –a or /etc/redhat-release
94. What is the difference between TCP and UDP?
Search online
95. What is a zombie process?
Search online
96. How do you search for a pattern/word in a file and then replace
it in an entire file?
sed command
97. Explain the purpose of “touch” command?
To create an empty file
98. If a command hangs, how to stop it and get the prompt back?
Ctrl C
99. Which command is used to count words or lines?
wc
100. How to check the number of users logged in?
who
101. What is the command to view the calendar of 2011?
cal 2011
102. Which command is used to view disk space?
df –h
103. How to create a new group in Linux?
groupadd
104. What is the command to send a message to everyone who is logged
into the system?
wall
105. Which command is used to check total number of disks?
fdisk –l
106. What is an mail server record in DNS?
MX
107. What does the following command line do?
ps -ef | awk '{print $1}' | sort | uniq
List the first column of all running processes, sort them and
remove duplicates
108. You get a call that when a user goes to www.yourwebsite.com it
fails and gets an error, how do you troubleshoot?
Check for user internet
Check to see if user computer has DNS for hostname lookup
Check to see if the server is up that is running that website
Check to see if the server’s web service is running
Check for DNS availability which is resolving that website
109. List 4 different directories in /?
/etc, /bin, /tmp, /home
110. What is the output of the following command:
$tail -10 filename | head -1
It will show the first line from the last 10 lines of a file
111. What are the different fields in /etc/passwd file?
Search online
112. Which command is used to list the processes?
ps –ef
113. What is the difference between “hostname” and “uname” commands?
Hostname will give you system name and uname will give you OS
information
114. How to check system load?
top and uptime command
115. How to schedule jobs?
crontab and at
116. What is the 3rd field when setting up crontab?
Day of the month
117. What is the command to create a new user?
useradd
118. What is the “init #” for system reboot?
6
119. How to restart a service?
systemctl restart servicename
120. How to shutdown a system?
shutdown or init 0
121. What is “ftp” command used for?
To transfer files from one computer to another
122. Explain cron job syntax? First is minute, second is..?
Min, house, day of the month, month, day of the week and command
123. How to delete a package in Linux?
rpm –e packagename
124. What is the file name where user password information is saved?
/etc/shadow
125. Which command you would use to find the location of chmod
command?
which chmod
126. Which command is used to check if the other computer is online?
ping othercomputer
127. Please explain about LAN, MAN and WAN?
Search online
128. How to list hidden files in a directory?
ls –la
129. What is the difference between telnet and ssh?
ssh is secure where telnet is not
130. How to run a calculator on Linux and exit out of it?
bc and quit
131. List any 4 commands to monitor system?
top, df –h, iostat, dmesg
132. You are notified that your server is down, list the steps you
will take to troubleshoot?
Check the system physically
Login through system console
Ping the system
Reboot or boot if possible
133. What is difference between static and DHCP IP?
Search online
134. How to write in vi editor mode?
i = insert, a = insert in next space, o = insert in new line
135. What is the difference between “crontab” and “at” jobs?
crontab is for repetitive jobs where at is for one time job
136. What is vCenter server in VMWare?
Search online
137. What is “dmidecode” command used for?
To get system information
138. What is the difference between SAN and NAS?
Search online
139. What is the location of system logs? E.g. messages
/var/log directory
140. How to setup an alias and what is it used for?
alias aliasname=”command”
It is used to created short-cuts for long commands
141. What is the purpose of “netstat” command?
Search online
142. What are terminal control keys, list any 3?
Crtl C, D and Z
143. Which command(s) you would run if you need to find out how many
processes are running on your system?
ps –ef | wc –l
144. What are the different types of shells?
sh, bash, ksh, csh etc.
145. How to delete a line when in vi editor mode?
dd
146. Which is the core of the operating system?
a) Shell
b) Kernel
c) Commands
d) Script
147. Which among the following interacts directly with system
hardware?
a) Shell
b) Commands
c) Kernel
d) Applications
148. How to save and quit from vi editor?
Shift ZZ or :wq!
149. What is the difference between a process and daemon?
Search online
150. What is the process or daemon name for NTP?
ntpd
151. What are a few commands you would run if your system is running
slow?
top, iostat, df –h, netstat etc.
152. How to install a package in Redhat Linux?
yum install packagename
153. What is the difference between “ifconfig” and “ipconfig”
commands?
ifconfig for Linux and ipconfig for Windows
154. What is the first line written in a shell script?
Define shell
e.g. #!/bin/bash
155. Where is the network (Ethernet) file located, please provide
exact directory location and file name?
/etc/sysconfig/network-scripts/ifcfg-nic
156. Why do we use “last” command?
To see who has logged in the system whether active or logged off
157. What is RHEL Linux stands for?
Search online
158. To view your command history, which command is used and how to
run a specific command?
history and history #
159. What is NTP and briefly explain how does it work and where is the
config files and related commands of NTP?
Search online
160. How to disable firewall in Linux?
Search online
161. How to configure mail server relay for sendmail service?
Edit /etc/mail/sendmail.mc file and add SMART_HOST entry
162. Where is samba log file located?
/var/log/samba
163. What is mkfs command used for?
To create a new filesystem
164. If you create a new group, which file does it get created in?
/etc/group
165. Which file has DNS server information (e.g. DNS resolution)?
/etc/resolv.conf
166. What are the commands you would run if you need to find out the
version and build date of a package (e.g. http)?
rpm –qi http
167. On the file permissions? What are the first 3 bits for and who is
it for?
Read, write and execute. They are used for the owner of the file
168. How to create a soft link?
ln –s
169. How to write a script to delete messages in a log file older than
30 days automatically?
Search online
170. How to quit out of “man” command?
q
171. Which command is used to partition disk in Linux?
fdisk
172. What is the difference between “shutdown” and “halt” command?
Search online
173. What is the exact syntax of mounting NFS share on a client and
also how to un-mount?
Search online
174. What experience do you have with scripting, explain?
if-the, do-while, case, for loop scripts
175. How to get information on all the packages installed on the
system?
rpm –qa
176. Explain VMWare?
Search online
177. You are tasked to examine a log file in order to find out why a
particular application keep crashing. Log file is very lengthy,
which command can you use to simplify the log search using a
search string?
grep for error, warning, failure etc. in /var/log/messages file
178. What is /etc/fstab file and explain each column of this file?
Search online
179. What the latest version of Windows server?
Search online
180. What is the exact command to list only the first 2 lines of
history output?
history | head -2
181. How to upgrade Linux from 7.3 to 7.4?
yum install update
182. How to tell which shell you are in or running?
$0
183. You have tried to “cd” into a directory but you have been denied.
You are not the owner of that directory, what permissions do you
need and where?
- - - - - - - r – x
184. What is CNAME record in DNS?
Entry for hostname to hostname
185. What is the name of VMWare operating system?
ESXi
186. What is the client name used to connect to ESXi or vCenter
server?
vSphere client
187. You get a call from a user saying that I cannot write to a file
because it says, permission denied. The file is owned by that
user, how do you troubleshoot?
Give write permission on the first 3 bits
188. What is the latest version of VMWare?
Search online
189. What is the name of firewall daemon in Linux?
firewalld
190. Which command syntax you can use to list only the 20th line of a
file?
Search online
191. What is the difference between run level 3 and 5?
3 = Boot system with networking, 5 = boot system with networking
and GUI
192. List a few commands that are used in troubleshooting network
related issue?
netstat, tcpdump etc.
193. What is the difference between domain and nameserver?
Search online
194. You open up a file and it has 3000 lines and it scrolled up
really fast, which command you will use to view it one page at a
time?
more or less
195. How to start a new shell. E.g. start a new ksh shell?
Simply type ksh, or bash
196. How to kill a process?
kill processID
197. How to check scheduled jobs?
crontab –l
198. How to check system memory and CPU usage?
free and top
199. Which utility could you use to repair the corrupted file system?
fsck
200. What is the command to make a service start at boot?
systemctl enable servicename
201. How to combine 2 files into 1? E.g. you 3 lines in file “A” and 5
lines in file “B”, which command syntax to use that will combine
into one file of 3+5 = 8 lines
cat fileA >> fileB
202. What is echo command used for?
To output to a screen
203. What does the following command do?
echo This year the summer will be great > file1
It will create a new file “file1” with the content as “This year
the summer will be great”
204. Which file to modify to allow users to run root commands
/etc/sudoers
205. You need to modify httpd.conf file but you cannot find it, Which
command line tool you can use to find file?
find / -name “httpd.conf”
206. Your system crashed and being restarted, but a message appears,
indicating that the operating system cannot be found. What is the
most likely cause of the problem?
The /boot file is most likely corrupted
Tuesday, 5 October 2021
Disable host key checking while connecting ssh in Linux
Environment and Prerequisite
- Linux
- SSH(OpenSSH)
Host Key Checking
- When we connect to remote server by using ssh, client compares client’s saved key and remote server’s key to authenticate server.
- This process prevents from Man-in-the-middle attack.
Disable Host Key Checking When Using SSH
- Remote host’s key will be added if there is no added key in
~/.ssh/known_hosts. - Connect to remote server even though saved key is different from server’s key.
1. Disable when using ssh command
- Use
StrictHostKeyChecking=nooption.
ssh -o StrictHostKeyChecking=no [DOMAIN_OR_IP]
2. Edit ssh config file
~/.ssh/config
- Add option to specific host like below.
Host twpower-private-server
HostName [IP ADDRESS]
StrictHostKeyChecking no
Port 22
User [USERNAME]
IdentityFile [IDENTITY KEY FILE]
/etc/ssh/ssh_config
- There is
*in config file. So this disables host key checking to all hosts. /etc/ssh/ssh_configdefines all the default settings for the client utilities for all users on that system.
Host *
StrictHostKeyChecking no
Sunday, 3 October 2021
Git Basic Tutorial
git init
git init
The git init command is the first command that you will run on Git. The git init command is used to create a new blank repository. It is used to make an existing project as a Git project. Several Git commands run inside the repository, but init command can be run outside of the repository.
The git init command creates a .git subdirectory in the current working directory. This newly created subdirectory contains all of the necessary metadata. These metadata can be categorized into objects, refs, and temp files. It also initializes a HEAD pointer for the master branch of the repository.
Command: git init
git add
The git add command is used to add file contents to the Index (Staging Area).This command updates the current content of the working tree to the staging area. It also prepares the staged content for the next commit. Every time we add or update any file in our project, it is required to forward updates to the staging area.
The git add command is a core part of Git technology. It typically adds one file at a time, but there some options are available that can add more than one file at once.
The "index" contains a snapshot of the working tree data. This snapshot will be forwarded for the next commit.
The git add command can be run many times before making a commit. These all add operations can be put under one commit. The add command adds the files that are specified on command line.
The git add command does not add the .gitignore file by default. In fact, we can ignore the files by this command.
Command: git add $(filename)
git commit
It is used to record the changes in the repository. It is the next command after the git add. Every commit contains the index data and the commit message. Every commit forms a parent-child relationship. When we add a file in Git, it will take place in the staging area. A commit command is used to fetch updates from the staging area to the repository.
The staging and committing are co-related to each other. Staging allows us to continue in making changes to the repository, and when we want to share these changes to the version control system, committing allows us to record these changes.
Commits are the snapshots of the project. Every commit is recorded in the master branch of the repository. We can recall the commits or revert it to the older version. Two different commits will never overwrite because each commit has its own commit-id. This commit-id is a cryptographic number created by SHA (Secure Hash Algorithm) algorithm.
Command: git commit
git clone
In Git, cloning is the act of making a copy of any target repository. The target repository can be remote or local. You can clone your repository from the remote repository to create a local copy on your system.
The git clone is a command-line utility which is used to make a local copy of a remote repository. It accesses the repository through a remote URL.
Command: git clone $(repository link)
git stash
Sometimes we want to switch the branches, but we are working on an incomplete part of your current project. we don't want to make a commit of half-done work. Git stashing allows us to do so. The git stash command enables you to switch branches without committing the current branch.
Generally, the stash's meaning is "store something safely in a hidden place." The sense in Git is also the same for stash; Git temporarily saves your data safely without committing.
Stashing takes the messy state of your working directory, and temporarily save it for further use.
Command: git stash
git ignore
In Git, the term "ignore" is used to specify intentionally untracked files that Git should ignore. It doesn't affect the Files that already tracked by Git.
Generally, the Ignored files are artifacts and machine-generated files. These files can be derived from your repository source or should otherwise not be committed.
Git ignore files is a file that can be any file or a folder that contains all the files that we want to ignore. The developers ignore files that are not necessary to execute the project. Git itself creates many system-generated ignored files. Usually, these files are hidden files. There are several ways to specify the ignore files. The ignored files can be tracked on a .gitignore file that is placed on the root folder of the repository. No explicit command is used to ignore the file.
There is no explicit git ignore command; instead, the .gitignore file must be edited and committed by hand when you have new files that you wish to ignore. The .gitignore files hold patterns that are matched against file names in your repository to determine whether or not they should be ignored.
There is no command in Git to ignore files; alternatively, there are several ways to specify the ignore files in git. One of the most common ways is the .gitignore file.
Steps to create .gitignore file in linux Step – 1
cat > .gitignore
*.txt
/newfolder/* Step – 2 Press Clt + D Step – 3
git add .gitignore
git commit -m "ignored directory created."
git origin master
The term "git origin master" is used in the context of a remote repository. It is used to deal with the remote repository. The term origin comes from where repository original situated and master stands for the main branch.
Master is a naming convention for Git branch. It's a default branch of Git. After cloning a project from a remote server, the resulting local repository contains only a single local branch. This branch is called a "master" branch. It means that "master" is a repository's "default" branch.
In most cases, the master is referred to as the main branch. Master branch is considered as the final view of the repo. Your local repository has its master branch that always up to date with the master of a remote repository.
In Git, The term origin is referred to the remote repository where you want to publish your commits. The default remote repository is called origin, although you can work with several remotes having a different name at the same time. It is said as an alias of the system.
The origin is a short name for the remote repository that a project was initially being cloned. It is used in place of the original repository URL. Thus, it makes referencing much easier.
Origin is just a standard convention. Although it is significant to leave this convention untouched, you could ideally rename it without losing any functionality.
Commands:
git pull origin master (is used to push the changes to the remote repository) git push origin master (is used to access the repository from remote to local)
git remote
In Git, the term remote is concerned with the remote repository. It is a shared repository that all team members use to exchange their changes. A remote repository is stored on a code hosting service like an internal server, GitHub, Subversion, and more. In the case of a local repository, a remote typically does not provide a file tree of the project's current state; as an alternative, it only consists of the .git versioning data.
To check the configuration of the remote server, run the git remote command. The git remote command allows accessing the connection between remote and local.
Command: git remote (want to see the original existence of your cloned repository)
git checkout
In Git, the term checkout is used for the act of switching between different versions of a target entity. The git checkout command is used to switch between branches in a repository.
The git checkout command operates upon three different entities which are files, commits, and branches. Sometimes this command can be dangerous because there is no undo option available on this command.
It checks the branches and updates the files in the working directory to match the version already available in that branch, and it forwards the updates to Git to save all new commit in that branch.
Command: git checkout $(branch_name)
git pull
The term pull is used to receive data from GitHub. It fetches and merges changes from the remote server to your working directory. The git pull command is used to pull a repository.
Pull request is a process for a developer to notify team members that they have completed a feature. Once their feature branch is ready, the developer files a pull request via their remote server account. Pull request announces all the team members that they need to review the code and merge it into the master branch.
The pull command is used to access the changes (commits)from a remote repository to the local repository. It updates the local branches with the remote-tracking branches. Remote tracking branches are branches that have been set up to push and pull from the remote repository. Generally, it is a collection of the fetch and merges command. First, it fetches the changes from remote and combined them with the local repository.
Command: git pull (repository link)
git push
The push term refers to upload local repository content to a remote repository. Pushing is an act of transfer commits from your local repository to a remote repository. Pushing is capable of overwriting changes; caution should be taken when pushing.
Moreover, we can say the push updates the remote refs with local refs. Every time you push into the repository, it is updated with some interesting changes that you made. If we do not specify the location of a repository, then it will push to default location at origin master.
The "git push" command is used to push into the repository. The push command can be considered as a tool to transfer commits between local and remote repositories.
Git push origin master is a special command-line utility that specifies the remote branch and directory. When you have multiple branches and directory, then this command assists you in determining your main branch and repository.
Generally, the term origin stands for the remote repository, and master is considered as the main branch. So, the entire statement "git push origin master" pushed the local content on the master branch of the remote location.
Command: git push origin master











