Devops = development + operations
Waterfall method used for one by one process approach.
Agile for sprints and faster high quality development of product.
Agile considers only development phase while devops considers both development
and operations phase.
The main objective of devops is to implement collaboration between development
and operations teams.
It is the process of continuous development, continuous build, continuous test,
continuous release of the software with high quality in very faster way with
automation tools.
Version control system:-
We can maintain all versions and also check entire info like who did recent changes,
owner, version and also bytes occupied, memory, permissions of file etc.
It can be used to share the code with peers for working on project.
Easy to administer.
We can recover previous version of file easily.
Working Directory: Where developers are required to create/modify files.
Repository: Where we have to store files and metadata. Here version control is
applicable. Here we can talk about versions like version-1, version-2 etc.
Commit: The process of sending files from working directory to the repository.
Checkout: The process of sending files from repository to working directory.
Types of version control systems:-
Centralized Version Control System:-
Everyone should use same repository.
Single point of failure.
Complexity increases as persons increase.
Dedicated network is required which causes performance issues.
Distributed version control systems with remote repository:-
Network is not required except for push and pull operations which involves server.
Each person has one repository each.
There is no single point of failure. Files can be recovered if lost.
High availability, Speed and there is no single point of failure are main reasons for
popularity of this model.
GIT:-
Git is Distributed Version Control System Tool.
Most people call it as global information tracker.
GIT is developed by Linus Torvalds(Finnish software engineer), who also developed
Linux Kenel.
Features of GIT:-
Distributed:-
Most operations are local
Staging Area:-
It is also known as index area.
There is logical layer/virtual layer in git between working directory and local
repository.
Working Directory Staging Area Local Repository
We cannot commit the files of working directory directly. First we have to add to the
staging area and then we have to commit.
Branching and Merging:-
We can create and work on multiple branches simultaneously and all these are
branches
are isolated from each other. It enables multiple work flows.
We can merge multiple branches into a single branch. We can commit branch wise
also.
Freeware and open source.
Supports for multiple platforms.
GIT Architecture:-
If the developer wants to share his work to the peer developers then he has to push
his local repository to the remote repository by using git push command.
New developer can get local repository by cloning remote repository.For this we
have to
use git clone command.
A developer can get updates from the remote repository to the local repository by
using
git pull command.
git add To add files from working directory to staging area.
git commit To commit changes from staging area to local repository.
git push To move files from local repository to remote repository.
git clone To create a new local repository from the remote repository.
git pull To get updated files from remote repository to local repository
working directory-> staging area -> local repository-> remote repository
stages of file in git:-
1)Untracked:
The files which are newly created in working directory and git does not aware of
these
files are said to be in untracked state.
2)Staged:
✽ The files which are added to staging area are said to be in staged state.
✽ These files are ready for commit.
3)In Repository/ Committed:
Any file which is committed is said to be In Repository/Committed State.
4)Modified:
Any file which is already tracked by git, but it is modified in working directory is said
to
be in Modified State
Installation of git on windows:-
https://git-scm.com/download/win
git –version
If we just type git, then we will get complete options available with git command.
Common git commands:-
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index
sparse-checkout Initialize and modify the sparse-checkout
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
mkdir project
cd project
now give git init inside project folder, then git .init file will be created.
git init -> This command will provide empty repository for our working directory, so
that version control is applicable for our workspace. The name of the empty
directory is .git, which is hidden directory.
Now project folder is acting as working directory.
If our working directory already contains local repository(.git), still if we call git init
command, then there is no impact.
Git status -> shows the status of current branch
Cat > file1: write something in this file
Ls: lists files in directory
git ls-files is used in Git to list all the files in the index (also known as the staging
area)
git add file1
Git Configurations before 1st Commit:-
git config --global user.email "[email protected]"
git config --global user.name "Durga"
git commit -m "Added two files a.txt and b.txt"
git log is used to display the commit history of a Git repository. It shows a list of
commits in reverse chronological order.(author, modified time etc)
git commit -a -m "Both files modified". But make sure this option will work only for
modified files, but not for newly created files. Combines git add and commit
commands.
Git status -s : gives concise output of files
Git add . : to add all files
Git add *.txt: to add all text files in working directory
echo -n "df4bb05e36e672698251e05e09d92ba45ea1fc47" | wc -c: 40
The first 7 characters also unique, by using that also we can identify commit.
This unique id is considered as hash, which is generated based on content of files.
The advantages of this hash are
1) Data inside our local repository is more secure.
2) git requires less space to store contents of files.
git commit -am "commit message"
git commit -ma "commit message" : won’t work
git log –help
git config –list: To list out all git configurations
git config user.name: To display user name
***Note: global means these configurations are applicable for all repositories
created by git. If we are not using global then it is applicable only for current
repository.
git config user.email: To display user email
What is create mode 100644 ?
The first 3 digits describe the type of file.
The next 3 digits describe the file permissions.
100 Means it is an ascii text file.
644 File permissions (rw-r--r--)
Git log command:-
git log file1.txt: shows history of particular file
git log –oneline: This option is very helpful if we have lot of commits and to identify
commit based on message.
git log -n 2: displays first two commits
git log -n 2 –oneline
git log --grep="pattern": It shows all commits which has given pattern in the commit
message.
git log --grep="added" –oneline
git log --since="5 minutes ago"
git log --since="2020-05-17"
git log –after=”2020-05-18”
git log --until="5 minutes ago"
git log --before="2020-05-17"
git log --author=Ravi –oneline
git log --author=Ravi
git log --decorate –oneline: This option will print some extra information like branch
information,head information, tags information etc.
git diff:-
git diff file1.txt
If any line prefixed with space means it is unchanged. If any line prefixed with +
means it is added in destination copy. If any line prefixed with - means it is removed
in destination copy. Prefix happens before the line of file in output.
git diff HEAD file1.txt
It shows the differences between working copy and last commit copy
git diff --staged HEAD file1.txt
git diff --staged file1.txt (#head is optional)
It shows the differences between staged copy and last commit copy.
git diff 7chracters_of_specified_commitid filename: To see the difference in File
Content between specific Commit and Working Directory Copy
git diff e5705a6 file1.txt
git diff --staged e5705a6 file1.txt: To see the difference in file content between
specific commit and staging area copy
git diff e5705a6 6745461 file1.txt: between two specific commits
git diff HEAD HEAD^ file1.txt: between last and last but one commit
HEAD -> Reference to last commit
HEAD^ or HEAD^1 or HEAD~1 -> Reference to last but one commit
git diff 6745461 be5256c: to see all files diff between two specified commits
git diff master test: between two branches
git diff master origin/master: To see the differences in Content between Local and
Remote Repositories
git diff --cached HEAD file1.txt: To compare staged copy with last commit copy
Removing files by using git rm command:-
To Remove Files from Working Directory and staging Area (git rm):-
git rm file1.txt
git rm -r: It will remove all files
git rm . : won’t work without -r
To Remove Files Only from staging Area (git rm --cached): git rm --cached file4.txt
Note: If we are not passing any argument,
$ git rm --cached
fatal: No pathspec was given. Which files should I remove?
To Remove Files Only from Working Directory (rm Command):- rm file1.txt
Git checkout command:-
We can use checkout command to discard unstanged changes in the tracked files of
working directory.
1) Only for working directory
2) To discard unstaged changes(The changes which are not added to staging area)
3) In the tracked files (The files which are already added to staging area/commit)
It is something like undo operation. It will copy contents of the file from index
area(staging area) to working directory.
git checkout – filename
git checkout -- file1.txt: It will discard any unstaged changes made in file1.txt.
Note: git checkout is applicable only for the files which are already tracked by git. It
is not applicable for new files.
git checkout: To discard changes in all tracked files of working directory
Note: git checkout command can be used in branching also.
Git references (master and HEAD):-
It is difficult to remember commit id. So we use reference names like head, master,
tags etc for executing those commands.
What is master?
1) master is the name of the branch.
2) It is a reference(pointer) to last commit id. Hence where ever we required to use
last
commit id, simply we can use reference master.
3) This information is available in .git/refs/heads/master file.
git show master
What is HEAD?
HEAD is a reference to master.
If any reference pointing to another reference, such type of reference is called
symbolic
reference. Hence HEAD is symbolic reference.
Bydefault HEAD is always pointing to branch(master).
Detached HEAD: Sometimes HEAD is not pointing to the branch name, such type of
head is considered as Detached HEAD.
Git reset command:-
git reset command is just like reset settings in our mobile.
There are 2 utilities of git reset command.
Utility-1: To remove changes from staging area
Utility-2: To undo commits at repository level
To Remove Changes from staging Area:-
git reset file1.txt
git rm --cached file1.txt
The file will be removed completely from staging area.
git reset file1.txt
The file won't be removed from staging area, but reset to previous state(one step
back).
git reset file1.txt
To ignore changes in staging area
git checkout -- file1.txt
To ignore changes in working directory
To undo Commits at Repository Level:-
Syntax:
git reset <mode> <commitid>
Moves the HEAD to the specified commit, and all remaining recent commits will be
removed.
mode will decide whether these changes are going t0 remove from staging area
and
working directory or not.
The allowed values for the mode are:
--mixed
--soft
--hard
--keep
--merge
To discard commits in the local repository and to discard changes in staging area we
should use reset with --mixed option.
git reset --mixed 86d0ca3
git reset --mixed HEAD~1
git reset HEAD~1
git reset --mixed HEAD~2
reset with --soft Option:-
git reset --soft HEAD~1
reset with --hard:
It is impossible to revert back and hence while using hard reset we have to take
special
care.
git reset --hard HEAD~2
Note:
If the commits are confirmed to local repository and to discard those commits we
can use
reset command.
But if the commits are confirmed to remote repository then not recommended to
use
reset command and we have to use revert command.
Git aliases:-
git config --global alias.one "log --oneline"
git one
Note: After creating alias name, we can use either alias name or original name.
git config --global alias.s "status"
All alias names will be stored inside .gitconfig file.
One=log
Git one: performs log command
Ignoring unwanted Files And Directories by using .gitignore File:-
touch a.txt b.txt Customer.java
touch logs/server.log logs/access.log
Any Special Treatment For Directories by Git:-
No special treatement for directories.
Git always consider only files but not directories.
Git never give any importance for the directories.
Whenever we are adding files from the directory, implicitly directory also will be
added.