SlideShare a Scribd company logo
1 of 53
Prepared by – Kumaresh Chandra Baruri
Software Engineer
 VCS is software tools that help software teams manage changes to source code over
time.
 It allows software teams work faster and smarter.
 VCS keeps track of every modification to the code in a special kind of database.
 Developers can turn back the clock and compare earlier versions of the code.
Version control system(VCS), also known as source control, is
the practice of tracking and managing changes to software code.
A distributed version control system (DVCS) brings a local copy of the
complete repository to every team member's computer, so they can
commit, branch, and merge locally.
■ Each developer has a complete, local repository.
■ Technically the central repository is not different from the local
repositories.
■ Easy to offline usage.
■ Easy to branch a project.
Examples: Git, Mercurial, Bazaar
Main features of git is-
 A DevOps tool used for source code management.
 Used to tracking changes in the source code.
 Enabling multiple developers to work together on non-linear development using
thousands of branches.
Git is a free and open source distributed version control system
designed to handle everything from small to very large projects
with speed and efficiency.
Git repository is like a data structure used by VCS to store metadata
for a set of files and directories. .git folder inside a project represents
a git repository.
There are two ways to obtain repository in the development PC-
1. Create a local repository and make it as Git repository.
Command: git init
2. Clone a remote repository (already exists on a server).
Command: git clone <Repository URL>
■ A Git repository has at most one working
tree.
■ Calculator is the project name.
■ Repository: .git folder which contains full
version of the project DB. Some of the files
are human readable.
■ Source codes: src folder
There are two types of repository.
files/folders next to the
.git folder are the
working tree
.git folder is the
Git repository Non-bare repository -
where working tree is
present.
.git folder is the
Git repository
Bare repository - where
working tree is not present.
Git branch is a pointer to a snapshot of the changes made by the
developer.
A new branch is derived when-
• A new feature is implemented.
•A bug is fixed.
master  What is currently in production.
staging contains the code that is being tested before going to
production.
testing source codes ready for testing. Testable build will be
prepared from here.
develop active development environment. Developer will create
pull request by targeting this branch.
feature currently being developed feature. Individual developer
will be working on this. From here, pull request will be created. After
completing the development, the branch will be deleted.
Initial
branch/
target
commit
Feature
Branch
Working
Tree
Staging
/Index Area
Modification in files
Send target files
to staging area
Commit and
push to repo
<working tree>
git checkout
1. git checkout branch name
populates the working tree with the latest commit of the
selected branch to start working from
2. git checkout -b <new-branch>
populates the working tree of the new branch with the
latest commit of the current branch.
3. git checkout -b <new_branch_name> <SHA1>
populates the working tree of the new branch with
<SHA1>.
<working tree>
Modification can be happened on the following contexts:
■ Modify, add, delete files
■ No need to tell Git which files you want to work on
■ Just tell Git which changes you intend to commit:
a) git add <file>: Add file by name
b) git rm <file>: Remove file
c) Git add * : Add all file etc.
<working tree>
git add <file-name>
Index or Staging Area is where the next commit is
prepared to push in repo:
■ git add and git rm update the index
■ Stage single hunks:
git add -p <file> : Add file to staging
area by name.
■ Unstage files:
git reset HEAD <file>
■ Git add * : Add all the files to staging area.
<working tree>
.git
git commit
 git commit commits staged changes only (the index).
Then, the file(s) is ready to push in repo.
 There can still be non-staged changes in the working
tree which will not be included into the commit.
<working tree>
.git
commit that was
checked out (HEAD)
git diff --staged
git diff
git diff HEAD
■ git status shows changed paths
○ between index and commit that was checked out (HEAD)
○ between working tree and index
■ git diff shows file modifications
○ details on next slide
A commit is kind of 'object' in git, and identifies and specifies a 'snapshot'
of the branch at the time of the commit.
Commit #01
A
B
C
A project consists of 3 files named –
1. A
2. B
3. C
These files are pushed to repo by 1st commit.
Commit 01
A
B
C
Commit 02
A1
B
C1
Commit 03
A1
time
■ Each and every individual commit is a
full snapshot of the whole project.
■ Commit 02 modified file A  A1 and
C C1.
■ Commit 3 modified C1 C2.
■ Git does not copies non modified file in
snapshot. Like- B is not changed in 2nd
commit, B amd A1 is not changed in
commit 3 and so on.
C2
B
Commit 01
Snapshot 01
Commit 02 Commit 03
time
Snapshot 03 Snapshot 03
Each commit knows its parent.
ID: 78ae51a
Snapshot
Parent: 6709af
Tree: 922b8c
Author:
John Doe
<jdoe@example.com>
Committer:
John Doe
<jdoe@example.com>
Commit Message
...
SHA1:
■ globally unique commit ID
■ 40-digit hexadecimal number
■ function of the commit object content
■ shown in git log output etc.
To inspect a commit use:
■ git show <SHA1>
■ git show --format=fuller <SHA1>
Once created commits are immutable.
■ Git sets author and committer based
on the user.name and user.email
config values.
■ Author can be explicitly set on
commit:
git commit --author=<author>
■ Author:
○ person who wrote the patch
■ Committer:
○ person who created the commit,
e.g. project maintainer who applied the
patch
First line is the subject, should be shorter
than 70 chars
Separate the body from the subject by an empty
line. The commit message should describe why
you are doing the change. That's what typically
helps best to understand what the change is
about. The details of what you changed are
visible from the file diffs.
The body can have as many paragraphs as you
want. Lines shouldn't exceed 80 chars. This
helps command line tools to render it nicely.
Paragraphs are separated by empty lines.
Bug: Issue #123
1. First line is the subject.
2. Separated by a blank line follows the
body.
3. The last paragraph is for metadata (key-
value pairs). The metadata is intended to
be interpreted by tools.
C
B
A
time
■ C is a successor of B
■ B is a successor of A
■ The lines between the commits represent parent
relationships, the arrows for parent relations are omitted.
■ Can be seen by:
○ git log (with file diffs)
○ git log --oneline (with subject only)
○ git log --graph (as graph)
○ gitk (as graph in Git repository browser)
G
B
A
feature2
C
feature
1
D
E
F
origin/master
bugfix10
master
HEAD
HEAD points to the current branch:
■ git commit updates the current branch
■ git checkout sets the current branch
G
B
A
feature
2
C
feature
1
D
E
F
origin/master
bugfix10
master
HEAD
HEAD
git checkout:
■ moves HEAD to newly
checked out branch .
■ also updates the working tree
■ a working tree with modifications is called dirty
■ a working tree without modifications is called clean
■ git stash puts changes in a dirty working tree
aside, with git stash pop they can be applied
somewhere else (more about conflict resolution
later)
If you started to make changes to the working tree
but the wrong branch is checked-out:
■ just try to checkout the correct branch, if there
are no conflicts this will just work
■ if there are conflicts the checkout fails,
in this case you can do:
$ git stash
$ git checkout <correct-branch>
$ git stash pop
$ <resolve conflicts>
$ git stash drop
C
B
A
D
master
HEAD git commit --amend rewrites the last commit:
■ creates a sibling commit D of the last commit
C and resets the current branch to it
■ the old commit message is preserved, but
can be edited if wanted
■ the old commit C is still available in the
repository
■ rewrites the history of the branch (you should
never rewrite commits that have already
been shared with others, since others may
already have used it as base for other work)
master
Add additional
changes to an
existing commit.
C
B
A
D
master
HEAD
Branches can be reset manually
git reset
git reset branch index working tree
--soft Yes No No
--mixed (default) Yes Yes No
--hard Yes Yes Yes
The branch is always reset, whether the
index and working tree are reset depends
on the reset mode (soft, mixed, hard).
With git reset --hard local
modifications in the working tree are lost.
■ git reset --hard:
Discard all local modifications.
■ git reset --soft:
Squash commits.
■ git reset --mixed:
Split commits.
C
B
A
D
master
HEAD
master
git reset B
git reset B
■ Updates the current branch to point to
commit B.
■ Commit C and D are no longer part of the
history of the master branch.
■ D and C are non-reachable.
C
B
A
D
master
Non-reachable commits
■ are by default kept for 2 weeks
■ are garbage collected after the expiry time has
passed and when
git gc is run
■ Can be checked out by SHA1.
HEAD
C
B
A
D
HEAD
master
If HEAD points directly to a commit (instead of
pointing to a branch) it’s called detached HEAD.
HEAD
HEAD
Detached
C
B
A
D
HEAD
master
New commits can be created even if HEAD is detached:
■ If you checkout something else now the new commit
gets unreachable (but you may still access it if you
know its SHA1).
HEAD
E
New commit
on Detached
HEAD
A tag allows to tag a specific point in the version
history:
■ normally used to tag important versions such as
releases
■ in contrast to branches tags are immutable (well
you can delete and recreate tags, but you really
should not do this once they have been shared with
others)
■ example: v1.0.0
■ full name: refs/tags/v1.0.0
B
A
C
stable-1.0
E
F
D
master
HEAD
v1.0.0
v1.0.1
There are 3 kind of tags:
■ lightweight tags (just a pointer to a commit)
■ annotated tags (full Git object, allows tags to have a
message)
■ signed tags (tag with signature)
Tag creation:
■ git tag <tagname>
■ git tag -a <tagname>
■ git tag -s <tagname>
List tags:
■ git tag
B
A
C
stable-1.0
E
F
D
master
HEAD
v1.0.0
v1.0.1
git fetch
 fetches new commits
 updates the remote tracking
branches
 never updates local branches
 never changes the working tree
 is always safe to do
 FETCH_HEAD points to the commit
that was fetched last
B
A
C
stable-1.0
E
F
D
master
HEAD
remote repository local repository
B
A
C
origin/stable-1.0
E
F
D
master
HEAD
origin/master
G G FETCH_HEAD
Used to download contents from a remote repository.
C
B
A
D
master
HEAD
E
F Feature_login
Merging
feature_login
to master
Git merging combines sequences of commits into one unified history of commits.
C
B
A
D
E
F feature_login
G
master
HEAD
master
git merge feature_login:
■ Merges feature_login into the current
branch (master).
■ Creates a merge commit (commit with
more than one parent).
■ The current branch is updated.
Cherry-pick enables arbitrary Git commits to be picked by reference and appended to the current
working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to
another. git cherry-pick can be useful for undoing changes
C
B
A
D
master
HEAD
E
F featureX
Here,
■ commit E implements a feature
■ commit F is bug-fix
■ the bug-fix F is needed in master
C
B
A
D
E
F featureX
Cherry-Pick:
■ Applies the modifications that were done by the commit
that is cherry-picked (the commit delta) to a new base.
■ The commit message is preserved.
■ The new commit has no parent relation to the commit
that was cherry-picked.
■ The cherry-pick can fail with conflicts. The conflict
resolution is done the same way as for conflicts on
merge.
G
master
HEAD
∆F
∆F
∆E
Rebasing is the process of moving or combining a sequence of commits to a
new base commit
Rebase:
■ redo the work that was done in the
featureX branch on top of the master
branch
C
B
A
D
master
HEAD
E
F featureX
Rebase:
■ rebases the current branch to a another base commit
■ rebase = series of cherry-picks
■ git rebase master rebases all commits of the
featureX branch (which is currently checked out) onto
the master branch.
■ the commit messages are preserved
■ the history of the featureX branch is rewritten, this is
bad if the featureX branch is shared and others have
based work on top of it
■ the old commits E and F still exist in the repository
■ after the rebase a fast-forward of master is possible
■ Linear history
■ ORIG_HEAD points to the old HEAD
C
B
A
D
master
E
F featureX
HEAD
G
H featureX
∆F
∆E
∆F
∆E
ORIG_HE
AD
Push:
■ pushes commits from the local repository to a
remote repository (more precisely from a local
branch to a remote branch)
■ git push origin HEAD:master
is equivalent to
git push origin
HEAD:refs/heads/master
■ git push origin master
is equivalent to
git push origin
refs/heads/master:refs/heads/master
git push origin HEAD:master
Name of remote
repository to which the
push is done.
What’s pushed to the
remote repository
(branch, commit, HEAD =
current branch).
Destination in the remote
repository (target
branch).
Situation:
■ The remote repository was
cloned, a local featureX
branch was created and in this
branch a commit C was created.
B
A
featureX C
HEAD
local repository remote repository
git push origin HEAD:master
B
A
master
origin/master
Push:
■ pushes commit C to the remote repository
■ updates the master branch in the remote
repository
■ The local branch name is never
transferred to the remote repository.
B
A
featureX C
HEAD
local repository remote repository
git push origin HEAD:master
B
A
master
origin/master
C
master
When Pushed
B
A
featureX
C
HEAD
local repository remote repository
git push origin HEAD:master
B
A
origin/master
D
Push:
■ pushes all commits which are
reachable from the pushed commit
and which are not available in the
remote repository
C
D
master
master
Situation:
■ The remote repository was
cloned, a local featureX branch
was created and in this branch a
commit C was created. In the
meantime master in the remote
repository was updated to
commit D.
B
A
featureX C
HEAD
local repository remote repository
B
A
master
origin/master
D
When Pushed
git push fails if the target branch
cannot be fast-forwarded to the
pushed commit.
B
A
featureX C
HEAD
local repository remote repository
B
A
master
origin/master
D
Force push:
■ Makes the push succeed even if the target
branch cannot be fast-forwarded.
■ The target branch is updated to the pushed
commit, conflicting commits are removed
from the history of the target branch!
■ After the force push commit D is no longer
contained in the history of the master
branch.
B
A
featureX C
HEAD
local repository remote repository
B
A
master
origin/master
D
git push --force origin HEAD:master
C
master
Pull:
■ git pull can be configured to do
git fetch +
git rebase instead (config parameter pull.rebase=true)
git pull = git fetch + git merge FETCH_HEAD
Pull is used to fetch and download content from a remote repository and immediately update the local
repository to match that content
1. https://www.simplilearn.com/tutorials/git-tutorial/what-is-git
2. https://www.atlassian.com/git/tutorials/what-is-version-control
3. https://www.geeksforgeeks.org/what-is-a-git-repository/
4. https://www.slideshare.net/kumareshbaruri/git-branching-policy-and-review-comments-prefix-246339744
5. https://www.atlassian.com/git/tutorials/syncing/git-
pull#:~:text=The%20git%20pull%20command%20is,Git%2Dbased%20collaboration%20work%20flows.
Introduction to git, a version control system

More Related Content

Similar to Introduction to git, a version control system

Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow Sebin Benjamin
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - WorkflowTahsin Abrar
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践Terry Wang
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践Terry Wang
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | WorkshopAnuchit Chalothorn
 
Git tech talk
Git tech talkGit tech talk
Git tech talkrazasayed
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git John Tighe
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of GitWayne Chen
 
Essential Git and Github commands
Essential Git and Github commandsEssential Git and Github commands
Essential Git and Github commandsIsham Rashik
 

Similar to Introduction to git, a version control system (20)

Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
 
Git
GitGit
Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git tech talk
Git tech talkGit tech talk
Git tech talk
 
Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git tips
Git tipsGit tips
Git tips
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
3 Git
3 Git3 Git
3 Git
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of Git
 
Essential Git and Github commands
Essential Git and Github commandsEssential Git and Github commands
Essential Git and Github commands
 

More from Kumaresh Chandra Baruri (10)

Introduction to OAuth2
Introduction to OAuth2Introduction to OAuth2
Introduction to OAuth2
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Fundamentasl of DFD
Fundamentasl of DFDFundamentasl of DFD
Fundamentasl of DFD
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Variations of git merging
Variations of git mergingVariations of git merging
Variations of git merging
 
Git branching policy and review comment's prefix
Git branching policy and review comment's prefixGit branching policy and review comment's prefix
Git branching policy and review comment's prefix
 
Introduction to flutter's basic concepts
Introduction to flutter's basic conceptsIntroduction to flutter's basic concepts
Introduction to flutter's basic concepts
 
WEB API Gateway
WEB API GatewayWEB API Gateway
WEB API Gateway
 
Model based testing using finite state machine(FSM)
Model based testing using finite state machine(FSM)Model based testing using finite state machine(FSM)
Model based testing using finite state machine(FSM)
 
Authentication and single sign on (sso)
Authentication and single sign on (sso)Authentication and single sign on (sso)
Authentication and single sign on (sso)
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 

Introduction to git, a version control system

  • 1. Prepared by – Kumaresh Chandra Baruri Software Engineer
  • 2.  VCS is software tools that help software teams manage changes to source code over time.  It allows software teams work faster and smarter.  VCS keeps track of every modification to the code in a special kind of database.  Developers can turn back the clock and compare earlier versions of the code. Version control system(VCS), also known as source control, is the practice of tracking and managing changes to software code.
  • 3. A distributed version control system (DVCS) brings a local copy of the complete repository to every team member's computer, so they can commit, branch, and merge locally.
  • 4. ■ Each developer has a complete, local repository. ■ Technically the central repository is not different from the local repositories. ■ Easy to offline usage. ■ Easy to branch a project. Examples: Git, Mercurial, Bazaar
  • 5. Main features of git is-  A DevOps tool used for source code management.  Used to tracking changes in the source code.  Enabling multiple developers to work together on non-linear development using thousands of branches. Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
  • 6. Git repository is like a data structure used by VCS to store metadata for a set of files and directories. .git folder inside a project represents a git repository. There are two ways to obtain repository in the development PC- 1. Create a local repository and make it as Git repository. Command: git init 2. Clone a remote repository (already exists on a server). Command: git clone <Repository URL>
  • 7. ■ A Git repository has at most one working tree. ■ Calculator is the project name. ■ Repository: .git folder which contains full version of the project DB. Some of the files are human readable. ■ Source codes: src folder
  • 8. There are two types of repository. files/folders next to the .git folder are the working tree .git folder is the Git repository Non-bare repository - where working tree is present.
  • 9. .git folder is the Git repository Bare repository - where working tree is not present.
  • 10. Git branch is a pointer to a snapshot of the changes made by the developer. A new branch is derived when- • A new feature is implemented. •A bug is fixed.
  • 11. master  What is currently in production. staging contains the code that is being tested before going to production. testing source codes ready for testing. Testable build will be prepared from here. develop active development environment. Developer will create pull request by targeting this branch. feature currently being developed feature. Individual developer will be working on this. From here, pull request will be created. After completing the development, the branch will be deleted.
  • 12. Initial branch/ target commit Feature Branch Working Tree Staging /Index Area Modification in files Send target files to staging area Commit and push to repo
  • 13. <working tree> git checkout 1. git checkout branch name populates the working tree with the latest commit of the selected branch to start working from 2. git checkout -b <new-branch> populates the working tree of the new branch with the latest commit of the current branch. 3. git checkout -b <new_branch_name> <SHA1> populates the working tree of the new branch with <SHA1>.
  • 14. <working tree> Modification can be happened on the following contexts: ■ Modify, add, delete files ■ No need to tell Git which files you want to work on ■ Just tell Git which changes you intend to commit: a) git add <file>: Add file by name b) git rm <file>: Remove file c) Git add * : Add all file etc.
  • 15. <working tree> git add <file-name> Index or Staging Area is where the next commit is prepared to push in repo: ■ git add and git rm update the index ■ Stage single hunks: git add -p <file> : Add file to staging area by name. ■ Unstage files: git reset HEAD <file> ■ Git add * : Add all the files to staging area.
  • 16. <working tree> .git git commit  git commit commits staged changes only (the index). Then, the file(s) is ready to push in repo.  There can still be non-staged changes in the working tree which will not be included into the commit.
  • 17. <working tree> .git commit that was checked out (HEAD) git diff --staged git diff git diff HEAD ■ git status shows changed paths ○ between index and commit that was checked out (HEAD) ○ between working tree and index ■ git diff shows file modifications ○ details on next slide
  • 18. A commit is kind of 'object' in git, and identifies and specifies a 'snapshot' of the branch at the time of the commit. Commit #01 A B C A project consists of 3 files named – 1. A 2. B 3. C These files are pushed to repo by 1st commit.
  • 19. Commit 01 A B C Commit 02 A1 B C1 Commit 03 A1 time ■ Each and every individual commit is a full snapshot of the whole project. ■ Commit 02 modified file A  A1 and C C1. ■ Commit 3 modified C1 C2. ■ Git does not copies non modified file in snapshot. Like- B is not changed in 2nd commit, B amd A1 is not changed in commit 3 and so on. C2 B
  • 20. Commit 01 Snapshot 01 Commit 02 Commit 03 time Snapshot 03 Snapshot 03 Each commit knows its parent.
  • 21. ID: 78ae51a Snapshot Parent: 6709af Tree: 922b8c Author: John Doe <jdoe@example.com> Committer: John Doe <jdoe@example.com> Commit Message ... SHA1: ■ globally unique commit ID ■ 40-digit hexadecimal number ■ function of the commit object content ■ shown in git log output etc. To inspect a commit use: ■ git show <SHA1> ■ git show --format=fuller <SHA1> Once created commits are immutable.
  • 22. ■ Git sets author and committer based on the user.name and user.email config values. ■ Author can be explicitly set on commit: git commit --author=<author> ■ Author: ○ person who wrote the patch ■ Committer: ○ person who created the commit, e.g. project maintainer who applied the patch
  • 23. First line is the subject, should be shorter than 70 chars Separate the body from the subject by an empty line. The commit message should describe why you are doing the change. That's what typically helps best to understand what the change is about. The details of what you changed are visible from the file diffs. The body can have as many paragraphs as you want. Lines shouldn't exceed 80 chars. This helps command line tools to render it nicely. Paragraphs are separated by empty lines. Bug: Issue #123 1. First line is the subject. 2. Separated by a blank line follows the body. 3. The last paragraph is for metadata (key- value pairs). The metadata is intended to be interpreted by tools.
  • 24. C B A time ■ C is a successor of B ■ B is a successor of A ■ The lines between the commits represent parent relationships, the arrows for parent relations are omitted. ■ Can be seen by: ○ git log (with file diffs) ○ git log --oneline (with subject only) ○ git log --graph (as graph) ○ gitk (as graph in Git repository browser)
  • 25. G B A feature2 C feature 1 D E F origin/master bugfix10 master HEAD HEAD points to the current branch: ■ git commit updates the current branch ■ git checkout sets the current branch
  • 26. G B A feature 2 C feature 1 D E F origin/master bugfix10 master HEAD HEAD git checkout: ■ moves HEAD to newly checked out branch . ■ also updates the working tree
  • 27. ■ a working tree with modifications is called dirty ■ a working tree without modifications is called clean ■ git stash puts changes in a dirty working tree aside, with git stash pop they can be applied somewhere else (more about conflict resolution later) If you started to make changes to the working tree but the wrong branch is checked-out: ■ just try to checkout the correct branch, if there are no conflicts this will just work ■ if there are conflicts the checkout fails, in this case you can do: $ git stash $ git checkout <correct-branch> $ git stash pop $ <resolve conflicts> $ git stash drop
  • 28. C B A D master HEAD git commit --amend rewrites the last commit: ■ creates a sibling commit D of the last commit C and resets the current branch to it ■ the old commit message is preserved, but can be edited if wanted ■ the old commit C is still available in the repository ■ rewrites the history of the branch (you should never rewrite commits that have already been shared with others, since others may already have used it as base for other work) master Add additional changes to an existing commit.
  • 29. C B A D master HEAD Branches can be reset manually git reset
  • 30. git reset branch index working tree --soft Yes No No --mixed (default) Yes Yes No --hard Yes Yes Yes The branch is always reset, whether the index and working tree are reset depends on the reset mode (soft, mixed, hard). With git reset --hard local modifications in the working tree are lost. ■ git reset --hard: Discard all local modifications. ■ git reset --soft: Squash commits. ■ git reset --mixed: Split commits.
  • 31. C B A D master HEAD master git reset B git reset B ■ Updates the current branch to point to commit B. ■ Commit C and D are no longer part of the history of the master branch. ■ D and C are non-reachable.
  • 32. C B A D master Non-reachable commits ■ are by default kept for 2 weeks ■ are garbage collected after the expiry time has passed and when git gc is run ■ Can be checked out by SHA1. HEAD
  • 33. C B A D HEAD master If HEAD points directly to a commit (instead of pointing to a branch) it’s called detached HEAD. HEAD HEAD Detached
  • 34. C B A D HEAD master New commits can be created even if HEAD is detached: ■ If you checkout something else now the new commit gets unreachable (but you may still access it if you know its SHA1). HEAD E New commit on Detached HEAD
  • 35. A tag allows to tag a specific point in the version history: ■ normally used to tag important versions such as releases ■ in contrast to branches tags are immutable (well you can delete and recreate tags, but you really should not do this once they have been shared with others) ■ example: v1.0.0 ■ full name: refs/tags/v1.0.0 B A C stable-1.0 E F D master HEAD v1.0.0 v1.0.1
  • 36. There are 3 kind of tags: ■ lightweight tags (just a pointer to a commit) ■ annotated tags (full Git object, allows tags to have a message) ■ signed tags (tag with signature) Tag creation: ■ git tag <tagname> ■ git tag -a <tagname> ■ git tag -s <tagname> List tags: ■ git tag B A C stable-1.0 E F D master HEAD v1.0.0 v1.0.1
  • 37. git fetch  fetches new commits  updates the remote tracking branches  never updates local branches  never changes the working tree  is always safe to do  FETCH_HEAD points to the commit that was fetched last B A C stable-1.0 E F D master HEAD remote repository local repository B A C origin/stable-1.0 E F D master HEAD origin/master G G FETCH_HEAD Used to download contents from a remote repository.
  • 38. C B A D master HEAD E F Feature_login Merging feature_login to master Git merging combines sequences of commits into one unified history of commits.
  • 39. C B A D E F feature_login G master HEAD master git merge feature_login: ■ Merges feature_login into the current branch (master). ■ Creates a merge commit (commit with more than one parent). ■ The current branch is updated.
  • 40. Cherry-pick enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes C B A D master HEAD E F featureX Here, ■ commit E implements a feature ■ commit F is bug-fix ■ the bug-fix F is needed in master
  • 41. C B A D E F featureX Cherry-Pick: ■ Applies the modifications that were done by the commit that is cherry-picked (the commit delta) to a new base. ■ The commit message is preserved. ■ The new commit has no parent relation to the commit that was cherry-picked. ■ The cherry-pick can fail with conflicts. The conflict resolution is done the same way as for conflicts on merge. G master HEAD ∆F ∆F ∆E
  • 42. Rebasing is the process of moving or combining a sequence of commits to a new base commit Rebase: ■ redo the work that was done in the featureX branch on top of the master branch C B A D master HEAD E F featureX
  • 43. Rebase: ■ rebases the current branch to a another base commit ■ rebase = series of cherry-picks ■ git rebase master rebases all commits of the featureX branch (which is currently checked out) onto the master branch. ■ the commit messages are preserved ■ the history of the featureX branch is rewritten, this is bad if the featureX branch is shared and others have based work on top of it ■ the old commits E and F still exist in the repository ■ after the rebase a fast-forward of master is possible ■ Linear history ■ ORIG_HEAD points to the old HEAD C B A D master E F featureX HEAD G H featureX ∆F ∆E ∆F ∆E ORIG_HE AD
  • 44. Push: ■ pushes commits from the local repository to a remote repository (more precisely from a local branch to a remote branch) ■ git push origin HEAD:master is equivalent to git push origin HEAD:refs/heads/master ■ git push origin master is equivalent to git push origin refs/heads/master:refs/heads/master git push origin HEAD:master Name of remote repository to which the push is done. What’s pushed to the remote repository (branch, commit, HEAD = current branch). Destination in the remote repository (target branch).
  • 45. Situation: ■ The remote repository was cloned, a local featureX branch was created and in this branch a commit C was created. B A featureX C HEAD local repository remote repository git push origin HEAD:master B A master origin/master
  • 46. Push: ■ pushes commit C to the remote repository ■ updates the master branch in the remote repository ■ The local branch name is never transferred to the remote repository. B A featureX C HEAD local repository remote repository git push origin HEAD:master B A master origin/master C master When Pushed
  • 47. B A featureX C HEAD local repository remote repository git push origin HEAD:master B A origin/master D Push: ■ pushes all commits which are reachable from the pushed commit and which are not available in the remote repository C D master master
  • 48. Situation: ■ The remote repository was cloned, a local featureX branch was created and in this branch a commit C was created. In the meantime master in the remote repository was updated to commit D. B A featureX C HEAD local repository remote repository B A master origin/master D When Pushed
  • 49. git push fails if the target branch cannot be fast-forwarded to the pushed commit. B A featureX C HEAD local repository remote repository B A master origin/master D
  • 50. Force push: ■ Makes the push succeed even if the target branch cannot be fast-forwarded. ■ The target branch is updated to the pushed commit, conflicting commits are removed from the history of the target branch! ■ After the force push commit D is no longer contained in the history of the master branch. B A featureX C HEAD local repository remote repository B A master origin/master D git push --force origin HEAD:master C master
  • 51. Pull: ■ git pull can be configured to do git fetch + git rebase instead (config parameter pull.rebase=true) git pull = git fetch + git merge FETCH_HEAD Pull is used to fetch and download content from a remote repository and immediately update the local repository to match that content
  • 52. 1. https://www.simplilearn.com/tutorials/git-tutorial/what-is-git 2. https://www.atlassian.com/git/tutorials/what-is-version-control 3. https://www.geeksforgeeks.org/what-is-a-git-repository/ 4. https://www.slideshare.net/kumareshbaruri/git-branching-policy-and-review-comments-prefix-246339744 5. https://www.atlassian.com/git/tutorials/syncing/git- pull#:~:text=The%20git%20pull%20command%20is,Git%2Dbased%20collaboration%20work%20flows.