Git For Devops Study Material
Git For Devops Study Material
Git For
DevOps
Study
Material
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
1 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
INDEX
Topic-1: Introduction to Devops ……………………………………………………………………………………… 8
Topic-6: Example-1 To Understand Working Directory, Staging Area and Local Repository
……………………………………………………………………………………………………………………………………... 34
Topic-7: The 6 Git Commands With Example - init,status,add,commit,log and config ……. 40
Topic-15: Git Aliases - Providing our own convenient names to git commands …………….. 84
Topic-16: Ignoring unwanted files and directories by using .gitignore file ……………………… 88
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
3 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Detailed Index
Topic-1: Introduction to Devops
1.1. What is Devops?
1.2. Water Fall Model
1.3. Agile Model
1.4. Water fall vs Scrum
1.5. Devops vs Agile Models
1.6. Top Important points about DevOps
Topic-6: Example-1 To Understand Working Directory, Staging Area and Local Repository
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
4 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Option-1: --oneline option to get brief log information
Option-2: -n option to limit the number of commits to display
Option-3: --grep option to search based on given pattern in commit message
Option-4: Show commits more recent than a specific time.
Option-5: Show commits older than a specific time
Option-6: Show commits based on author
Option-7: --decorate option to display extra information
Topic-15: Git Aliases - Providing our own convenient names to git commands
Topic-16: Ignoring unwanted files and directories by using .gitignore file
Topic-17: Any Special Treatment for directories by Git ???
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
5 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-18: Branching And Merging
18.1. What is branching?
18.2. Need of creating a new branch
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
6 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-21: Working with Remote Repositories
21.1) Need of Remote Repositories
21.2) How to work with GitHub?
21.3) How to create account in GitHub?
21.4) How to create a new reposioty in Github?
21.5) How to work with Remote Repository?
1) git remote
2) git push
3) git clone
4) git pull
5) git fetch
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
7 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 1
Introduction
to DevOps
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
8 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 1: Introduction
to DevOps
1.1) What is Devops?
1.2) Water Fall Model
1.3) Agile Model
1.4) Water fall vs Scrum
1.5) Devops vs Agile Models
1.6) Top Important points about DevOps
For any software development,release and maintenance, there are two groups of
engineers will work in the company.
1) Development Group
2) Non-Development Group or Operations Group or Administrators Group.
1) Development Group:
The people who are involving
1) planning
2) coding
3) build
4) Testing
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
9 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Eg:
Business Analyst(BA)
System Analyst(SA)
Design Architech(DA)
Developers/coders
Build Engineer
Test Engineers/QA
2) Operations Group:
The people who are involving
1) Release
2) Deploy
3) Operate
4) Monitor
Eg:
Release Engineers
Configuration Engineer
System Admin
Database Admin
Network Admin
etc
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
10 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
To understand this new Devops culture, we have to aware already existing SDLC Models.
1) Waterfall Model
2) Prototype Model
3) Incremental/Iterative Model
4) Spiral Model
5) RAD Model
6) Big-Bang Model
7) Fish Model
8) V Model
9) Agile Model
Requirement
Gathering
Requirement
Analysis
Design
Coding
Testing
Release
Maintenance
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
11 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Advantages:
1) It is very simple and easy to implement.
2) Phases won't be overlapped and hence there is no ambiguity.
3) All phases will be executed one by one which gives high visibility to the project
managers and clients about the progress of the project.
4) Best suitable if the requirements are fixed.
5) Best suitable for small projects.
Disadvantages:
1) It is very rigid model b'z it won't accept requirement changes in the middle.
2) Client satisfaction is very low because most of the times client will add new
requirements in the middle,which won't be supported.
3) Total project development time is more because testing should be done after
complementing development only.
4) The cost of bug fixing is very high because we cannot identify bugs in the early stages
of life cycle.
5) Not suitable if the requirements keep on changing.
6) Not suitable for large projects.
Among all these models Scrum model is the most popular and frequently used model.
Scrum is derived from Rugby Game.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
12 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Points to Remember:
1) Scrum is an agile model that allows us focus on delivering highest quality software in
shortest time.
2) In this model software developement follows increment by increment
3) Each increment will take one to 3 weeks duration.
4) 7 to 9 members are responsible in every sprint.
The art of doing the twice work in half time is nothing but scrum model Juff sutherland
Limitations:
1) The chances of project failure is very high if individuals are not committed or
cooperative
2) Adapting scrum model for large teams is very big challenge
3) Must required experienced and efficient team members
4) If any team member leaves in the middle of project,it can have a huge negative impact
on the project.
Similarities:
1) Both are software development methodologies. Agile is there in the market for the
last 20 years, but devops is recent methodology.
2) Both models concentrating on rapid development of software project.
Differences:
1) The differences between these models will starts after development of the project.
Agile methodology always talks about software development,testing and deployment.
Once deployment completed agile methodology has no role.
But Devops model will continue after deployment also and it is also responsible for
operations and monitoring.
2) In Agile Model, separate people are responsible for developing, testing, and deploying
the software. But, in DevOps, the DevOps engineer is responsible for everything;
development to operations, and operations to development.
4) Agile model always giving highest priority for speed, where as Devops giving proirity
for both speed and automation.
5) In Agile, client is responsible to give the feedback for the sprint. But in Devops,
immediate feedback is available from the monitoring tools.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
14 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
What is Devops?
Devops is not a new Tool/Technology in the market.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
15 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
16 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic – 2
Introduction
to
Version Control System
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
17 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-2: Introduction to
Version Control System
2.1) Need of Version Control System?
2.2) How version control system will work?
2.3) The basic terminology of version control system
2.4) Benefits of Version Control System
2.5) Types of Version Control Systems
2.5.1) Centralized Version Control System
2.5.2) Distributed Version Control Systems
client project
|--100 files developed
|- client suggested some changes
|- I changed some files source code to meet client requirement
|- I gave the demo and client suggested some more changes
|- I changed some files source code to meet client requirement
|- I gave demo 3rd time
|- Client asked for first version only
|- My Face with big ????
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
18 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
2) Every change should be tracked like
who did the change
when he did the change
which changes he did etc
and all changes should be maintained.
3) Overwriting of the code should not be happend.
4) Developers have to share their code to peer developers, so that multiple developers
will work in collaborative way.
5) Parallel development must be required
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
19 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
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.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
20 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
2) All commit and checkout operations should be performed by connecting to the central
repositoty via network. If network outage, then no version control to the developer.
i.e in this type, developer work space and remote repository server should be
connected always.
3) All commit and checkout operations should be performed by connecting to the central
repositoty via network and hence these operations will become slow, which causes
performance issues. No local operations and every version control operation should be
remote operation.
1) The checkout and commit operations will be performed locally. Hence performance is
more.
2) To perform checkout and commit operations network is not required. Hence if there is
any network outage, still version control is applicable.
3) If something goes wrong to any repository there is a chance to recover. There is no
question of single point of failure.
4) To perform push and pull operations network must be required, but these operations
are not most common operations and we are performing very rarely.
Note:
1) commit and checkout operations will be performed between workspace and
repository.
work space – commit Repository
Repository – checkout workspace
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
22 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
The main job of remote repository is just to share our work to peer developers.
High availability, Speed and there is no single point of failure are main reasons for
popularity of this model.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
23 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic – 3
Features
And
Architecture
of
GIT
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
24 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
1) Distributed
Git is developed based on Distributed Version Control System Architecture.
Because of Distributed Architecture it has several advantages:
A) Every Developer has his own local repository. All the operations can be performed
locally.Hence local repo and remote repo need not be connected always.
B) All operations will be performed locally, and hence peformance is high when compared
with other VCSs. i.e it is very speed
C) Most of operations are local. Hence we can work offline most of the times.
D) There is no single point failure as Every Developer has his own local repository.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
25 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
2) Staging Area:
It is also known as index area.
There is logical layer/virtual layer in git between working directory and 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.
This staging area is helpful to double check/cross-check our changes before commit.
This type of layer is not available in other Version Control Systsem Tools like CVS, SVN etc
Git stores files in repository in some hash form, which saves space.
GIT will uses internally snapshot mechanism for this. All these conversions and taking
snapshots of our data will be happened in staging area before commit.
Eg: If a sample repository takes around 12 GB space in SVN where as in GIT it takes hardly
420 MB.
We can merge multiple braches into a single brach. We can commit branch wise also.
4. Moving files in GIT is very easy as GIT automatically tracks the moves. Whereas in other
VCS we need to create a new file & then delete the old one.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
26 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
For every developer, a separate local repository is available. Developer can perform all
checkout and commit operations wrt local repository only.
To perform commit operation, first he has to add files to staging area by using git add
command, and then he has to commit those changes to the local repository by using git
commit command. Hence commit in GIT is a 2-step process.
commit is applicable only for staging area files but not for working directory files.
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.
Remote repository contains total project code, which can be accessible by all developers.
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.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
27 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
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.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
28 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic – 4
Life Cycle
of
File in GIT
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
29 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
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.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
30 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 5
Git Installation
On
Windows
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
31 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
https://git-scm.com/download/win
2.26.2
Git-2.26.2-64-bit.exe
If we just type git, then we will get complete options available with git command.
lenovo@DESKTOP-ECE8V3R MINGW64 ~
$ git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
32 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
These are common Git commands used in various situations:
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
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
33 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic – 6
Example-1 To Understand
Working Directory,
Staging Area and
Local Repository
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
34 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 ~
$ cd d:
lenovo@DESKTOP-ECE8V3R MINGW64 /d
$ mkdir gitprojects
lenovo@DESKTOP-ECE8V3R MINGW64 /d
$ cd gitprojects
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects
$ mkdir project1
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects
$ cd project1
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/project1
Now project1 acts as working directory. We have to request git, to provide version control
for this directory. For this we have to use git init command.
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.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
35 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Note:
1) If our working directory contains any files, then these files won't be added to the local
repository bydefault, we have to add explicitly.
2) If our working directory already contains local repository(.git), still if we call git init
command, then there is no impact.
No commits yet
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
a.txt
b.txt
nothing added to commit but untracked files present (use "git add" to track)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
36 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/project1 (master)
$ git add a.txt b.txt
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: a.txt
new file: b.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
37 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
no changes added to commit (use "git add" and/or "git commit -a")
But make sure this option will work only for modified files, but not for newly created files.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
38 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
commit 9a33a5b2e0d1c90eff544a3710b599be3c22665e
Author: Durga <[email protected]>
Date: Thu May 14 22:16:59 2020 +0530
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
39 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic – 7
The 6 Git Commands With Example
1) init
2) status
3) add
4) commit
5) log
6) config
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
40 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
1) git init
Once we creates workspace, if we want version control, then we require a local
repository. To create that local repository we have to use git init command.
$ git init
Initialized empty Git repository in D:/gitprojects/project1/.git/
2) git status:
It shows the current status of all files in each area, like which files are untracked, which
are modified, which are staged etc.
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: a.txt
modified: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git status -s
M a.txt
M b.txt
A c.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
41 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
3) git add:
To add files from working directory to staging area for tracking/commiting purpose, we
have to use git add command.
4) git commit:
If we want to commit staged changes, then we have to use git commit command.
For every commit, a unique commit id will be generated. It is of 40-length hexadecimal
string.
$ echo -n "df4bb05e36e672698251e05e09d92ba45ea1fc47" | wc -c
40
The first 7 characters also unique, by using that also we can identify commit.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
42 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
For every commit, git records author name,mail id, timestamp and commit message.
We can add files to staging area and we can commit changes by using a single command
But this command will work only for tracked files but not for new files.
5) git log:
It shows history of all commits.
It provides commit id, author name,maild , timestamp and commit message.
6) git config:
We can use this command to configure git like user name, mail id etc
git config --global user.email "[email protected]"
git config --global user.name "Durga"
***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.
We can change user name and mail id with the same commands
7) $git ls-files
This command will listout all files which are tracked by git.
8) $ls
This command will listout all files present in workspace
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
44 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 8
The Complete Postmortem
of
git log Command
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
45 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ git log
commit 48437a7ad2ada6e18a26b127ca101c0ebf45b19e (HEAD -> master)
Author: Durga <[email protected]>
Date: Thu May 7 21:09:33 2020 +0530
commit 3a8051f59110f9696f4e0f922f438cbb6bb7694d
Author: Durga <[email protected]>
Date: Thu May 7 21:06:58 2020 +0530
commit 4b77312160c82d76395558da415a96b2a8b36072
Author: Durga <[email protected]>
Date: Thu May 7 21:05:25 2020 +0530
commit 93d297b69e048046b8ff5dba140b5889f1b47500
Author: Durga <[email protected]>
Date: Thu May 7 20:59:22 2020 +0530
commit d49f79120beecb2ea9e34b8398b4ee78bf662bf4
Author: Durga <[email protected]>
Date: Thu May 7 20:52:12 2020 +0530
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
46 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
commit d49f79120beecb2ea9e34b8398b4ee78bf662bf4
Author: Durga <[email protected]>
Date: Thu May 7 20:52:12 2020 +0530
Note: There are multiple options are availble for git log command to see the history.
git log --help
Output:
7 characters of commit id + commit message
***This option is very helpful if we have lot of commits and to identify commit based on
message.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
47 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Syntax:
-<number>
-n <number>
--max-count=<number>
Limit the number of commits to output.
$ git log -n 2
commit b7bd0cfecb7cd64128f209a1de4cc0ffefdd9310 (HEAD -> master)
Author: Ravi <[email protected]>
Date: Sat May 16 21:23:23 2020 +0530
commit 44fe2785f2e3f30ebcf733ffdc278ce240364488
Author: Durga <[email protected]>
Date: Sat May 16 21:05:07 2020 +0530
It shows all commits which has given pattern in the commit message.
*** This option is very helpful if we follow a particular structure for the commit message.
We can use this option to find all commits related to a particular request number or
defect number etc.
commited a.txt
commit b7bd0cfecb7cd64128f209a1de4cc0ffefdd9310
Author: Ravi <[email protected]>
Date: Sat May 16 21:23:23 2020 +0530
Note: There are multiple options are availble for git log command to see the history of all
commits.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
50 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 9
The Complete Story
of
git diff Command
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
51 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Demo Example:
file1.txt
First line in file1.txt
Second line in file1.txt
file2.txt
First line in file2.txt
Second line in file2.txt
file1.txt
First line in file1.txt
Second line in file1.txt
Third line in file1.txt
Fourth line in file1.txt
file2.txt
First line in file2.txt
Second line in file2.txt
Third line in file2.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
52 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Fourth line in file2.txt
file1.txt
First line in file1.txt
Second line in file1.txt
Third line in file1.txt
Fourth line in file1.txt
Fifth line in file1.txt
file1.txt
First line in file1.txt
Second line in file1.txt
Third line in file1.txt
Fourth line in file1.txt
Fifth line in file1.txt
sixth line in file1.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
53 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
2) index 0e17c9d..e3e329f 100644
0e17c9d hash of source file content
e3e329f hash of destination file content
100644 git file mode
First 3 characters(100) represents the type of file.
100 means ASCII text file.
Next 3 characters represents the file permissions.
644 rw-r--r--
3)--- a/file1.txt
--- means missing lines in staged copy
4) +++ b/file1.txt
+++ means new lines added in working directory version
5) @@ -3,3 +3,4 @@
-3,3
- means source version
@@ -3,3 +3,4 @@
Second line in file1.txt
Third line in file1.txt
Fourth line in file1.txt
Fifth line in file1.txt
+sixth line in file1.txt
Clear indication that one line added in the working directory copy when compared with
staged copy.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
54 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Case-2: To see the difference in File Content between
Working Directory and Last Commit
The last commit can be referenced by HEAD.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
55 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Case-4: To see the difference in File Content between
specific Commit and Working Directory Copy
git diff 7chracters_of_specified_commitid filename
Eg:
$ git diff e5705a6 file1.txt
diff --git a/file1.txt b/file1.txt
index d4effe0..e3e329f 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1,2 +1,6 @@
First line in file1.txt
Second line in file1.txt
+Third line in file1.txt
+Fourth line in file1.txt
+Fifth line in file1.txt
+sixth line in file1.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
56 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Case-6: To see the difference in File Content between 2
specified Commits:
$ git log --oneline
6745461 (HEAD -> master) 2 files and each file contains 4 lines
e5705a6 2 files and each file contains 2 lines
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
58 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Case-9: To see the differences in Content between 2
Branches
$ git diff master test
It shows all differences between master branch and test branch
Summary:
git diff <path>
Shows the differences in the content of working directory, staging area and local
repostiory.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
59 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
7) git diff HEAD HEAD~1 file1.txt
To compare content in the file between last commit and last but one commit.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
60 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 10
Helix Visual Merge Tool
(p4merge)
For
Checking Differences
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
61 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
We can use P4Merge tool for both comparison and merging purposes.
https://www.perforce.com/
downloads
skip registration
P4MERGE will provide multiple utilities, But we require only Merge and Diff Tool.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
62 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Select only Merge and Diff Tool.
$ p4merge
bash: p4merge: command not found
Mergetool Configurations:
git config --global merge.tool p4merge
git config --global mergetool.p4merge.path "C:\Program Files\Perforce\p4merge.exe"
git config --global mergetool.prompt false
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
63 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Note: p4merge tool can be used to compare only one file at a time.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
64 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 11
Removing Files
by
using git rm Command
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
65 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
git rm file1.txt
git rm --cached file1.txt
General Linux rm command
git rm file1.txt
file1.txt will be removed from staging area and from working directory
$ git rm .
fatal: not removing '.' recursively without -r
It won't work because we didn't use -r option.
$ git rm -r .
It will remove all files
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
66 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ ls
file4.txt file5.txt
$ ls
file1.txt file2.txt
$ rm file1.txt
Note:
1) git rm file1.txt It will remove file from both working directory and staging area
2) git rm --cached file1.txt It will remove file only from staging area but not from
working directory
3) rm file1.txt It will remove file only from working directory but not from staging area.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
68 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 12
Undo Changes
with
git Checkout Command
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
69 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
It is something like undo operation. It will copy contents of the file from index
area(staging area) to working directory.
Eg:
$ git checkout -- file1.txt
It will discard any unstaged changes made in file1.txt.
After executing this command, staged copy content and working directory content is
same.
$ cat file1.txt
first line in file1.txt
second line in file1.txt
This is third line in file1.txt
This is fourth line in file1.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
70 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ cat file1.txt
first line in file1.txt
second line 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.
Summary:
git checkout -- file.txt
To discard changes in working directory copy.
git checkout
To discard changes in all tracked files of working directory.
git checkout
If we are not passing any argument, then this command will show the list of eligible files
for checkout.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
71 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic – 13
Git References
(master and HEAD)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
72 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Git provides some sample names for these commit ids. We can use these names directly.
These are just pointers to commit ids. These sample names are called references or refs.
Eg:
$pwd
/d/gitprojects/project6/.git/refs/heads
$ cat master
49aa8d79a9bab4c0d72dec217c0c6d5d96d604ce
Most of the times, we have to use the most recent commit id.
For such type of most commonly used commit ids git provides default references.
What is master?
$ git status
On branch master
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
73 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
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.
$ cat HEAD
ref: refs/heads/master
Detached HEAD:
Sometimes HEAD is not pointing to the branch name, such type of head is considered as
Detached HEAD.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
74 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 14
Git reset
Command
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
75 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Changes already added to staging area, but if we don't want to commit, then to remove
such type of changes from staging area, then we should go for git reset.
It will bring the changes from staging area back to working directory.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
76 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/project7 (master)
$ vi file1.txt
First line in file1.txt
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.txt
nothing added to commit but untracked files present (use "git add" to track)
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file1.txt
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.txt
nothing added to commit but untracked files present (use "git add" to track)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
77 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Q) We modified the content of the file1.txt and added to staging area. But we
want to ignore those changes in staging area and in working directory. For
this requirement which commands we required to use?
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.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
78 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
1) --mixed Mode:
It is the default mode.
To discard commits in the local repository and to discard changes in staging area we
should use reset with --mixed option.
It won't touch working directory.
Example:
vi file1.txt
First line in file1.txt
vi file2.txt
First line in file2.txt
vi file3.txt
First line in file3.txt
To discard commit-3:
git reset --mixed 86d0ca3
git reset --mixed HEAD~1
git reset HEAD~1
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
79 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ git log --oneline
59e6cd7 (HEAD -> master) file3 added again
86d0ca3 file2 added
9165d34 file1 added
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file2.txt
file3.txt
nothing added to commit but untracked files present (use "git add" to track)
Note:
1) It is not possible to remove random commits.
2) --mixed will work only on repository and staging area but not on working directory.
3) whenever we are using --mixed, we can revert the changes, because changes are
available in working directory.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
80 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ git log --oneline
1979e61 (HEAD -> master) file3 added again
4d32eb3 file2 added again
9165d34 file1 added
The commits will be discarded only in local repository, but changes will be there in
working directory and staging area
$ git ls-files
file1.txt
file2.txt
file3.txt
Use Cases:
1) If some files are missing in the last commit, then add those files and commit again.
2) We forgot to add defect number in commit message.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
81 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
To remove recent two commits permanently:
2. --soft
Changes will be discarded only in local repository.
It won't touch staging area and working directory.
Working tree won't be clean.
But we can revert with
git commit
3. --hard
Changes will be discarded everywhere.
Working tree won't be clean.
No way to revert.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
82 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
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.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
83 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic - 15
Git Aliases –
Providing our own Convenient Names
to
git Commands
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
84 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Note: After creating alias name, we can use either alias name or original name.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
85 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Q2) Create alias Name 's' to the following git Command?
git status
$ git s
git: 's' is not a git command. See 'git --help'.
$ git config --global alias.s "status"
$ git s
On branch master
nothing to commit, working tree clean
Note: If we use git in original command while creating alias name, what will happend?
$ git config --global alias.ss "git status"
.gitconfig:
[user]
name = Ravi
email = [email protected]
[core]
autocrlf = true
[diff]
tool = p4merge
[difftool "p4merge"]
path = C:\\Program Files\\Perforce\\p4merge.exe
[difftool]
prompt = false
[merge]
tool = p4merge
[mergetool "p4merge"]
path = C:\\Program Files\\Perforce\\p4merge.exe
[mergetool]
prompt = false
[alias]
one = log --oneline
s = status
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
86 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
We can perform any changes in alias commands based on requirement.
one = log
$ git one
commit bb26af3c6875a480ee0f92883ba85af5048eec6f (HEAD -> master)
Author: Ravi <[email protected]>
Date: Tue May 26 19:40:13 2020 +0530
commit 257073dcecf4364b77e8c64dbd7386a71f4071a2
Author: Ravi <[email protected]>
Date: Tue May 26 12:38:38 2020 +0530
file1 added
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
87 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic – 16
Ignoring unwanted Files
And
Directories by using .gitignore File
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
88 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
.gitignore File:
We have to create this file in working directory.
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
Customer.java
a.txt
b.txt
logs/
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
89 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
nothing added to commit but untracked files present (use "git add" to track)
.gitignore:
# Don't track a.txt
a.txt
#Don't track all .txt files
*.txt
#Don't track log files
logs/
#Don't track any hidden file
.*
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
90 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic – 17
Any Special Treatment
For
Directories by Git?
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
91 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ git status
On branch master
nothing to commit, working tree clean
$ mkdir dir1
Even though we created dir1, GIT won't give any importance for this directory because it
does not contain any files.
$ git status
On branch master
nothing to commit, working tree clean
$ touch dir1/{a..d}.py
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
dir1/
nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: dir1/a.py
new file: dir1/b.py
new file: dir1/c.py
new file: dir1/d.py
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
92 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-18
Branching
And
Merging
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
93 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
18.1. What is branching?
While working on real time projects code base, branching is one of mandatory and
unavoidable concept.
Till now whatever files created and whatever commits we did, all these happend in master
branch.
master branch is the default branch/ main branch in git.
Generally main source code will be placed in master branch.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
94 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
95 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Conclusions:
1. Once we creates a branch all files and commits will be inherited from parent branch to
child branch. Branching is a logical way of duplicating files and commits. In the child
branch we can create new files and we can perform new commits based on our
requirements.
2. All branches are isolated to each other. The changes performed in master branch are
not visible to the new branch and the changes performed in the new branch are not
visible to the master branch.
3. Once the work completed in new branch then we can merge that new brach to the
main branch or we can push that branch directly to the remote repository.
1) To View Branches:
To know all available branches in our local repository, we have to use git branch
command.
git branch
- It will show all branches in our local repository.
- By default we have only one branch: master
- master is the default name provided by GIT.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
96 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ git branch
* master
* indicates that master is current active branch.
Note:
There is another way to check on which branch currently we are working, for this we have
to use git status command.
$ git status
On branch master
nothing to commit, working tree clean
Eg:
$ git branch new1branch
It will create a new branch: new1branch
$ git branch
* master
new1branch
Eg:
$ git checkout new1branch
Switched to branch 'new1branch'
$ git branch
master
new1branch
* new2branch
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
100 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Important Conclusions:
1. All branches are isolated to each other. The changes performed in master branch are
not visible to the new branch and the changes performed in the new branch are not
visible to the master branch.
But in other version control systems like SVN, if we want to create a branch, first we have
to create a new directory and we have to copy all files manually to that directory which is
very difficult job and time consuming job.
3. In Git, if we switch from one branch to another branch just HEAD pointer will be moved,
beyond that no other work will be happend. Hence implementing branching concept is
very easy and very speed.
Note: In GIT Branching, new directory won't be created and files won't be copied and just
HEAD pointer will be changed. Hence to implement branching zero affort is required in
GIT.
2. If we required to work on hot fixes of production code, then we can create branch for
the production code base and we can work on that branch. Once work completed then we
can push the fixed code to the production.
Most of the real time projects have a separate production branch to handle this type of
requirements.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
101 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
4. To test new technologies or new ideas without effecting main code base, branching is
the best choice.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
102 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
18.6) Advantages of Branching:
1. We can enable Parallel development.
2. We can work on multiple flows in isolated way.
3. We can organize source code in clean way.
4. Implementing new features will become easy
5. Bug fixing will become easy.
6. Testing new ideas or new technologies will become easy.
Demo Example:
Assume new feature implemented properly, We want to merge feature branch with
master branch.
In the fast-forward merge, git simply moves parent branch and points to the last commit
of the child branch.
If same file modified by both parent and child branches then conflicts will be raised. In
fast-forward merge there is no chance of any conflicts, because updations happened only
in child branch and we didn't touch parent branch.
Note: After creating child branch if parent branch also contains some new commits, then
fast-forward merge won't be happend and Three-way merge will be happed.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
107 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
18.9) What is Three-Way Merge?
If changes present in both parent and child branches and if we are trying to perform
merge operation, then git will do three-way merge.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
108 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/project10 (feature)
$ git add z.txt ; git commit -m 'c2f'
[feature 6a9b808] c2f
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 z.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
109 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/project10 (feature)
$ git checkout master
Switched to branch 'master'
In this case new commits are available in both parent and child branches.
If we are trying to perform merge operation, git will do three-way merge.
Three-way merge creates a new commit which is also known as merge commit.
Parent branch will pointing to the newly created merge commit.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
110 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/project10 (master)
$ git log --oneline --graph
* 65afca1 (HEAD -> master) Merge branch 'feature'
|\
| * 6a9b808 (feature) c2f
| * 488588b c1f
* | 56fccfa c3m
|/
* 56e0980 c2m
* 9e65e9f c1m
If there is a conflict then GIT stops the merge process and provides conflict message.
Git will markup both branches content in the file to resolve the conflict very easily.
Once we completed editing of the file with required final content, then we have to add to
the staging area followed by commit. With that merging process will be completed.
Demo Example:
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects
$ mkdir project12
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
114 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/project12 (master|MERGING)
$ git add a.txt ; git commit -m 'Resolved Merge Conflicts'
[master 63f541a] Resolved Merge Conflicts
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
115 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Eg:
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/project12 (master)
$ git branch
feature
* master
After deleting the branch, still files and commits are available because the changes are
merged to master branch.
Note:
If we want to combine all commits of feature branch into a single commit and merge that
commit to the master branch, then we should go for squash option.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
117 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-19
Merging
By using
Rebase
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
118 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
19.1 Process of rebasing
19.2. Demo Example for rebasing
19.3. Advantages of rebasing
19.4. Disadvantages of rebasing
19.5 Differences between Merge and Rebase
Step-2: We have to merge feature branch into the master branch(fast-forwar merge will
be happend)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
119 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Step-1: We have to rebase feature branch on top of master branch.
Whatever new commits are there in the feature branch will be duplicated by git.
Here everything(like commit message,timestamp,author name and mail) is same except
that commit ids will be changed.
The base commit of the feature branch(duplicate copy) will be updated as last commit of
parent branch(master branch).
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
120 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Step-2: We have to merge feature branch into the master branch (fast-forwar merge will
be happend)
The master branch pointer will be changed to last commit(duplicate copy) of the feature
branch. In this case Fast-forward merge will be happend.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
121 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
122 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/rebasing (feature)
$ git checkout master
Switched to branch 'master'
c3m
commit d2369f5d777eff029551b018fd4800d3471fbebf
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:39:44 2020 +0530
c2m
commit 27458a4980b808ac346efa86ede08ea49c3f1719
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:39:33 2020 +0530
c1m
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/rebasing (master)
$ git log feature
commit 56661b62bd8b81cbe5347ac4e6bc9cc57a8850d8 (feature)
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:40:59 2020 +0530
c2f
commit a7de761b18a07f44c34cd88a01c204d4c68df697
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:40:39 2020 +0530
c1f
commit d2369f5d777eff029551b018fd4800d3471fbebf
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:39:44 2020 +0530
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
123 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
c2m
commit 27458a4980b808ac346efa86ede08ea49c3f1719
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:39:33 2020 +0530
c1m
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/rebasing (master)
$ git log --oneline master
76f925d (HEAD -> master) c3m
d2369f5 c2m
27458a4 c1m
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
124 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
c2f
commit d96d3ae369b5d9394615baa4ea5fd1393016cc04
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:40:39 2020 +0530
c1f
commit 76f925d5bc1f019c0d37aeb2019428c02a1bd9a2 (master)
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:41:39 2020 +0530
c3m
commit d2369f5d777eff029551b018fd4800d3471fbebf
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:39:44 2020 +0530
c2m
commit 27458a4980b808ac346efa86ede08ea49c3f1719
Author: Ravi <[email protected]>
Date: Wed Jun 3 12:39:33 2020 +0530
c1m
Step-2: We have to merge feature branch into the master branch (fast-forwar merge
will be happend)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
126 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Note:
Rebase is very dangerous operation and it is never recommended to use on public
repositories because it rewrites history.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
127 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-20
Stash
in
GIT
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
128 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
20.1 What is git stash?
20.2 Demo Example for stashing
20.3 How to list all available stashes?
20.4 How to check the contents of stash?
20.5 How to perform unstash?
20.6 Partial Stash
20.7 How to delete the stash?
Eg-1:
Stash Store (something) safely in a hidden or secret place.
Eg: Most of billionaire shashed their welath in Swiss banks"
Eg-2:
Doctor op is going on (6PM to 9PM)
An urgent case came Doctor will pause op and then he look into urgent case
After completing our urgent work, we can bring these stashed changes to our current
working directory.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
129 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Note:
1. Stashing concept is applicable only for tracked files but not for newly created files.
2. To perform stashing, atleast one commit must be completed.
$ git stash
You do not have the initial commit yet
$ git stash
No local changes to save
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
130 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/stashing (master)
$ git add file2.txt
Assume we required to create and work on file3.txt and and this file changes needs to be
committed immediately.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
131 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
nothing added to commit but untracked files present (use "git add" to track)
no changes added to commit (use "git add" and/or "git commit -a")
Dropped stash@{0} (775eb1616fe54fec28cd0e0a3a7b52fabba34d21)
no changes added to commit (use "git add" and/or "git commit -a")
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/stashing (master)
$ cat file1.txt
First Line in File1
Work is going on...
no changes added to commit (use "git add" and/or "git commit -a")
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
134 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/stashing (master)
$ git stash list
It is empty
no changes added to commit (use "git add" and/or "git commit -a")
Saved working directory and index state WIP on master: 9484eab first commit
no changes added to commit (use "git add" and/or "git commit -a")
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (76459eecb1b350caf56349b94cb2f091a371a7d0)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
137 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Demo Example:
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects
$ mkdir stashdelete
no changes added to commit (use "git add" and/or "git commit -a")
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
139 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
no changes added to commit (use "git add" and/or "git commit -a")
no changes added to commit (use "git add" and/or "git commit -a")
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
140 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/stashdelete (master)
$ git stash list
stash@{0}: WIP on master: df0ba71 3 files added
stash@{1}: WIP on master: df0ba71 3 files added
FAQs:
1) What is stash?
2) How to perform stash?
3) How to perform unstash?
4) What is the Difference between pop and apply?
5) what is partial stash?
6) How to delete all stashes?
7) How to delete a particular stash?
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
141 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-21
Working
with
Remote Repositories
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
142 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
If we required to share our code to the peer developers/team members then the remote
repository concept will come in the picture.
As GIT is distributed version control system, every developer has his own local repository.
Every developer can share his code to the peer developers/team members.
By using push operation, developer can share his code the peer developer.
By using pull operation, developer can get the code of peer developer.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
143 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
The Problems if Developer communicates directly with other Developers:
1. On every developer's machine we have to install Git Server.
2. Every developer should aware hostname and port number of all remaining developers,
then only he can share the code.
3. If there is any change in port number of any developer's machine, intimating this for all
developers every time is very difficult task.
Note:
1. Using common remote repository is best practice in real time.
2. The most common service providers of remote repositories
Github,Gitlab,Bitbucket etc
3. Some big companies may use their own common remote repository instead of using 3rd
party repositories.
4. Sometimes in Real time we may required to work with multiple remote repositories
also.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
144 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
We have to signup with our mail id. We should use valid mail id only because we have to
verify that mail id to create account successfully.
github requires email verification.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
145 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
146 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Repository Name is the name of the project folder. We have to choose meaningfull name.
Note:
1. The max allowed file size in Github public repository: 100MB
2. The max allowed repo size in Github public repository: 2GB
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
147 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
1) git remote:
We can use git remote command to configure remote repository to our local repository.
$ git remote add <alias_name> remote_repository_url
Eg:
$ git remote add origin https://github.com/durgadevops88/github_project.git
Here, origin is alias name of the remote_repository_url. By using this alias name only we
can communicate with remote repository.
Instead of origin we can use any name, but it is convention to use origin.
By using git remote command we can also view remote repository information.
$ git remote
It just provides the alias names of remote repositories
$ git remote -v
It provides remote repository urls also.
2) git push:
We can use git push command to send our changes from local repository to remote
repository. ie to push our changes from local repo to remote repo.
Demo Example:
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects
$ mkdir remoterepo
second commit
commit 074137633893c093572e4a35923579ac9dbf61be
Author: Ravi <[email protected]>
Date: Sun Jul 19 20:27:53 2020 +0530
first commit
Being a Developer, i want to share to this code to my peer developers. We have to send
this code to the remote repository, so that it is available for them.
We have to configure remote repository to our local repository. For this we have to use git
remote command.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
150 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Note: Whenever we are using remote repository the communication will be happend
between local and remote repositories only.
Assume we created a new repository named with github_project2 and its url is
https://github.com/durgadevops88/github_project2.git
We have to send the files of local repository to this remote repository also.
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/remoterepo (master)
$ git remote add my_remote https://github.com/durgadevops88/github_project2.git
Note: By using settings tab of remote repository we can perform multiple activities
like changing ownership,delete repository etc.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
151 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
3) git clone:
cloning means creating exactly duplicate copy.
Eg:
git clone https://github.com/durgadevops777/github_project.git
Now the project name will become repository project name.
Note: Based on our requirement we can provide a new name for the project.
git clone <remote_repo_url> <new_project_name>
Demo Example-1 :
lenovo@DESKTOP-ECE8V3R MINGW64 /d
$ mkdir newdeveloper
lenovo@DESKTOP-ECE8V3R MINGW64 /d
$ cd newdeveloper/
second commit
commit dc9556591b99a10a7e0d99a8ae88b9fe99db1edf
Author: Ravi <[email protected]>
Date: Sun Jul 19 21:51:05 2020 +0530
first commit
Demo Example -2: With our own customized Project Folder Name
lenovo@DESKTOP-ECE8V3R MINGW64 /d/newdeveloper
$ git clone https://github.com/durgadevops777/github_project.git my_project
Cloning into 'my_project'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 8 (delta 0), reused 5 (delta 0), pack-reused 0
Receiving objects: 100% (8/8), done.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
153 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/newdeveloper/my_project (master)
$ ls -la
total 7
drwxr-xr-x 1 lenovo 197121 0 Jul 22 20:52 ./
drwxr-xr-x 1 lenovo 197121 0 Jul 22 20:52 ../
drwxr-xr-x 1 lenovo 197121 0 Jul 22 20:52 .git/
-rw-r--r-- 1 lenovo 197121 25 Jul 22 20:52 _config.yml
-rw-r--r-- 1 lenovo 197121 12 Jul 22 20:52 file1.txt
-rw-r--r-- 1 lenovo 197121 12 Jul 22 20:52 file2.txt
Syntax:
$ git pull <remote> <branch>
$ git pull origin master
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
154 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Demo Example:
On Developer A Machine:
lenovo@DESKTOP-ECE8V3R MINGW64 /d
$ mkdir dev_A_work_space
lenovo@DESKTOP-ECE8V3R MINGW64 /d
$ cd dev_A_work_space/
Now we have to create a remote repository in the github named with remote_repo.
The corresponding url is:
https://github.com/durgadevops777/remote_repo.git
On Developer B Machine:
Developer B is responsible to clone this remote repository into local repository and he can
do some updates.
lenovo@DESKTOP-ECE8V3R MINGW64 /d
$ mkdir dev_B_work_space
lenovo@DESKTOP-ECE8V3R MINGW64 /d
$ cd dev_B_work_space/
DevB has to update these changes to the remote repository by using git push command.
git pull To download and merge those updates with local repo.
We can use directly git pull without using git fetch.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
157 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/dev_A_work_space (master)
$ ls
file1.txt
Note:
1. To perform push operation, local repository and remote repository should be in sync. ie
the local repository should be upto date to the remote repository.
If any updates in remote repo, git push is not allowed. It will ask us to pull first.
2. If any conflicts are there, we have to sit with peer developer to resolve the conflicts.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
158 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-22
Git Tagging
(git Tag Command)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
159 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
160 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
V-1.0.0.0 tag acts as a permanent reference to the current latest commit. But based on our
requirement we can define a tag for old commits also.
We can use tag directly where ever commit id is required in our commands.
For the specified commitid, if any tag is defined then we can use directly that tag instead
of commit id.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
161 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Demo Example:
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects
$ mkdir tagging
Instead of using commit id we can use the corresponding tag in our commands.
fourth commit
fourth commit
Summary:
git tag <tagname>
git tag --list
git tag --delete <tagname>
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
165 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Symantic Versioning:
Almost all software products follow Symantic Versioning.
V 1.2.12
Where 1 is considered as Major version.
2 is considered as Minor version.
12 is considered as Patch version.
We can get more info on semantic versioning from the following url: https://semver.org/
Note: First Alpha Release and then Beta Release and then finally original major version
release.
We can create annotated tag by using git tag command with -a option.
$ git tag -a <tagname>
Here -a indicates that it is annotated tag.
Now default editor will be opened for tag message.
Demo Example:
$ git log --oneline
f7ec107 (HEAD -> master) fifth commit
2a1c1f4 (tag: V-1.0.0) fourth commit
b83ee22 third commit
ce4a690 second commit
121a2cb first commit
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
166 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/tagging (master)
$ git log --oneline
f7ec107 (HEAD -> master, tag: V-1.1.0) fifth commit
2a1c1f4 (tag: V-1.0.0) fourth commit
b83ee22 third commit
ce4a690 second commit
121a2cb first commit
fourth commit
Release 1.1.0
fifth commit
LightWeight tag is not implemented as object but Annotated tag implemented as object.
Release 1.1.0
error: no signature found
Annotated tag information will be stored in .git/refs/tags folder and .git/objects folder.
$ cat .git/refs/tags/V-1.1.0
378a767274b8e2991b6fcfa9d987fe6ec25fd34b
$ cat .git/objects/37/8a767274b8e2991b6fcfa9d987fe6ec25fd34b
x%▒A
▒0=▒▒▒%ٲ ▒Ѓ▒m▒ ▒6)▒*▒{+▒▒23BY[▒SE'▒▒1a▒▒4Y▒▒▒
%%▒▒ul▒RD▒▒x\lg;▒▒▒]▒uzm▒▒▒▒չT▒▒J-
5▒▒Be▒▒v▒▒3=:▒▒▒`o▒xf▒Y▒{_*▒/▒
To know the type of object, we have to use -t option with cat-file command.
To print the information of object, we have to use -p option with cat-file command.
Release 1.1.0
Note: Extra information maintained by Annotated Tag when compared with Light Weight
tag and hence it is recommended to use Annotated Tag.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
170 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Release 1.0.0 Beta Corrected
third commit
Note: For the same commit we can define multiple tags also based on our requirement.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
172 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Whenever we are using push command, only code pushed to the remote repository but
not tags.
tag-2.JPG
Observe releases link in github repository page, you can see this tag.
From there, you can download complete source code upto that release.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
173 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Now, the tag V-1.0.0-beta deleted from the remote repository, but not from local
repository.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
174 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-23
git revert
Command
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
175 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ git reset c2
After c2, all the next commits will be deleted.
Suppose if this code already pushed to the remote repository and already several people
pulled this code and starts working on that code,git reset command may create big
problem.
git reset command deletes commit history and hence it is destructive command and not
recommended to use on public repositories.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
176 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
$ git revert C3
git will revert the changes of C3, means with state of C2, a new commit will be created.
In git revert, commit history won't be deleted and hence there is no effect on peer
developers. It is safe operation.
There is difference in the last commit and last but one commit.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
179 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects
$ mkdir revertdemo2
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: file1.txt
no changes added to commit (use "git add" and/or "git commit -a")
Note:
With git revert we can use -n option also.
-n or --no-commit
Usually the git revert command automatically creates some commits with commit log
messages stating which commits were reverted. This flag applies the changes necessary to
revert the named commits to your working tree and the index, but does not make the
commits. In addition, when this option is used, your index does not have to match the
HEAD commit. The revert is done against the beginning state of your index.
This is useful when reverting more than one commits' effect to your index in a row.
file1.txt
git add file1.txt
file2.txt
git add file2.txt
file3.txt
git add file3.txt
git commit '3 files modified'
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
182 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-24
Cherry-Picking
(git cherry-pick Command)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
183 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-24: Cherry-Picking
(git cherry-pick Command)
24.1) Need of Cherry-Picking
24.2) Use cases of cherry-pick
24.3) Demo Example for cherry-picking
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
184 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Note:
1. When every we are using cherry-pick command, a brand new commit object will be
created but with same changes of the picked commit of feature branch.
2. Cherry-pick may cause duplicate commits and hence in most of the scenarios we can
use merge operation instead of cherry-pick.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
187 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
3. We can use -n or --no-commit option with cherry-pick, in that case new commit won't
be created. This is helpful whenever we are doing cherry-picking multiple commits. With
all these changes we can create a single commit.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
188 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
Topic-25
git reflog
Command
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
189 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
Git For DevOps
We can use git reflog command to know only local repository operations but not remote
repository operations.
Syntax:
$ git reflog
It will show all git operations performed on local repository.
By mistake if we did any unwanted destruction operation( like git reset --hard), still we
can recover by using git reflog command.
Demo Example:
lenovo@DESKTOP-ECE8V3R MINGW64 /d/gitprojects/reflogdemo
$ git init
Initialized empty Git repository in D:/gitprojects/reflogdemo/.git/
Note: Whatever options we can use with log command, all those options can be used for
reflog also.
Q) By Mistake if we did git reset --hard Command and some Files got removed from Local
Repository. Is it possible to recover those changes OR not?
Yes. For this purpose we can use git reflog command.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
194 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]