SlideShare a Scribd company logo
VCS / SCM
Source control /Version control is the management
of changes to documents, computer programs and
other collections of information
git is a source code management system.
WHAT GIT IS NOT
* git is neither Github or Bitbucket
SOME BENEFITS OF GIT
DATA REDUNDANCY AND REPLICATION
Since there are multiple full repositories on multiple machines
(instead of one central repository), the risk of project loss due to
server failure or some other catastrophe is much lower.
HIGH AVAILABILITY
High availability -- Server down? Network down? No problem.
Work in your repo (commit, view history, branch, etc) to your
heart's content.Try that with Subversion!
SUPERIOR DISK UTILIZATION AND NETWORK
PERFORMANCE
Git efficiently compresses the objects in the .git directory, saving
you space.
COLLABORATION FRIENDLY
Git makes it easy to collaborate on projects with groups of
contributors and with great services like Bitbucket, Gitlab and (of
course) Github, git's collaboration friendliness is even further
magnified.
SETUP
git config —global user.name “John Doe”
git config —global user.email “johndoe@example.co”
INITIALIZING A GIT REPO
$ git init
A git repo is usually a directory that is tracked by git. Git tracks the states
of the files in the directory and with various commands, informs you of
the status of you repository.
To start tracking a directory (to initialize a git repo):
The stages of any file in a git repository
How git thinks about its data.
* One key difference that we need to mention a bit is the way git thinks about
data in comparison to how other VCS. Most other systems (CVS, Subversion,
Perforce etc.) store information as a list of file-based changes
fig: file-based changes
* Git thinks of its data more like a set of snapshots of a miniature filesystem.
Every time you commit, or save the state of your project in Git, it basically takes a
picture of what all your files look like at that moment and stores a reference to
that snapshot.
fig: changes as snapshots
Simply put, a branch in Git is a lightweight movable pointer to a
commit.
Commits are snapshots of your repository.These snapshots usually
contain/reference other git object types.
COMMITS
BRANCHES
The image shows how
a commit is
represented in the
repository
Pointer to that root tree and all the commit metadata
(some) Git commands
Git status
Arguably the most typed command on the git cli, it displays paths that have
differences between the index file and the current HEAD commit, paths that have
differences between the working tree and the index file, and paths in the working
tree that are not (yet) tracked by Git (and are not ignored by ‘gitignore’)
$ git status
Git add
In order to begin tracking a new file, you use the command git add.
What this command does is to update the ‘index’ using the current content found in
the working tree to prepare the content stages for the next commit.
$ git add <file_name>
Suppose you have a lot of changes in a file and you don’t want to commit all the
changes at once:
$ git add <file_name> -p
The ‘-p’ flag interactively chooses chunks in the file to add to the ‘index’ or staging area.
Git commit
Stores the current contents of the index in a new commit along with a log message
from the user describing the changes.
$ git commit
If you have changes in the working directory and you really want to add all files with
a simple commit message
$ git commit —amend
To change/update the last commit - in the event that you don’t like the commit
message or to add another file to the same commit.
$ git commit -am “my super awesome commit message”
* Note that any file you have in the index gets added when you use this commit option and yeah, it rewrites history so
use carefully.
$ git cat-file -p <commit_sha>
Since we should now have a commit, lets take a minute to examine it - or
any random commit on your system
After a few hours of
moving bits around
and a bunch of
commits, our repo
‘kinda’ looks like this
*conceptually*
Remember: Git thinks of its data more like a set of snapshots
of a miniature filesystem
*The “master” branch in Git is not a special branch. It is exactly like any other branch.The only reason
nearly every repository has one is that the git init command creates it by default and most people
don’t bother to change it.
Which when looked at from a birds eye view, looks ‘something’ like this:
$ git branch testing
* By default, the `git branch` command makes the tip of the
branch the HEAD
Now we have 2 branches pointing to the same commit object
f30ab…
$ git checkout master
$ git branch testing
$ git show-ref master
$ git show-ref testing
Let’s confirm that both branches actually point to the
same commit object
* We’ll talk a bit about ‘checkout’ soon.
Since we’ve seen that a branch is simply a pointer to a commit
object - identified by a ‘sha’, it’s fairly easy to select commits as
bases for our new branches.
$ git branch <branch_name> [<start-point>] (source: man git-branch)
Creating a branch with a start point.
$ git branch feature/authentication-patch 34ac55…
HEAD
How does Git know what
branch you’re currently
on?
Easy, It keeps a special
pointer called HEAD
The HEAD is just a pointer to
the currently checked out branch.
$ cat .git/HEAD
$ git checkout testing
* ’checking out’ the testing branch switches HEAD to the testing branch
CHECKOUT
Git checkout is a very useful command that alters the working tree.
Updates files in the working tree to match the version in the index or the specified
tree. If no paths are given, git checkout will also update HEAD to set the specified
branch as the current branch.
It moves HEAD to a different branch (or commit) and updates the working
directory to match it.
$ git checkout <branch_name>
Note that any uncommitted change will be lost during a checkout so Git
forces you to stash or commit before checking out to another branch.
This is also the reason why when you need to remove the changes made
on a file you use:
$ git checkout <file_name>
Detached HEAD
The HEAD becomes ‘detached’ when you checkout to a valid commit
that isn’t a branch.
$ git checkout 34ac55…
This can be used to quickly check inspect an old version of your
project.
* Being in the ‘detached head’ state can however be dangerous
because if you checkout to a grandparent of HEAD for instance and
then make commits, you loose being able to get back the commits
even after switching to other branches.
GIT OBJECTS
• Blobs
The git “blob” type is just a bunch of bytes that could be anything, like a text file, source
code, or a picture, etc.
• Trees
A git tree is like a filesystem directory.A git tree can point to, or include Git “blob”
objects or other git trees.
• Commits
A git commit object includes:
Information about who committed the change/check-in/commit, a pointer to the git tree
object that represents the git repository when the commit was done and the parent
commit to this commit (so we can easily find out the situation at the previous commit).
• Tags
A git tag object points to any git commit object. A git tag can be used to refer to a
specific tree, rather than having to remember or use the hash of the tree.
Inside .git
HEAD
config
description
hooks
pre-push.sample
post-update.sample
pre-commit.sample
info
objects
refs
[ a text file that is shown as project description in web frontend ]
[ repository wide configuration ]
[ text file showing currently checked out branch ]
[ where git hooks are stored ]
* Git hooks are scripts that run
automatically every time a particular
event occurs in a Git repository
[ use this file to ignore files (like .gitignore but isn’t versioned) ]exclude
[ Git’s internal warehouse for blobs, indexed by SHAs - where the ’objects’ are stored ]
[ Where refs (including) branches live ]
heads
remotes
tags
stash
[ where your git branches are managed ]
[ remote branches ]
[ … here be the tags ]
[ an ascii text file that has your stash SHAs ]
(other) Git commands
Git clone
The git clone command copies an existing Git repository to a new directory.
The “working copy” is a full-fledged Git repository—it has its own history, manages its
own files, and is a completely isolated environment from the original repository.
$ git clone <repo_url>
<repo_url> must be a valid ssh, git, ftp or http(s) url
…or even on a flash drive
$ git clone /<path_to_source> /<new_path>
$ git clone /path/to/source/repo /path/on/flash/drive
You can clone from and to your local filesystem.
* of course, the flash drive should be mounted
Git merge
The git merge command incorporates changes from the named commits
(since the time their histories diverged from the current branch)
into the current branch
Say we have a repository with 2 branches as shown below:
* see the git documentation for more options ( http://git-scm.com/book)
$ git checkout master
$ git merge iss53
Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this
merge and automatically creates a new commit that points to it.
This type of commit referred to as a merge commit, and is special in that it has more than one
parent.
The above commands leave our repository in a new state.
fig: merge commit
Merge conflicts
Sometimes, the merge between 2 branches may not go smoothly and you’ll have something
called a merge conflict.
$ git merge iss53
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
If your changes on the iss53 branch modified the same part of a file as a new
change on the branch being merged unto, you’ll get a merge conflict.
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: index.html
no changes added to commit (use "git add" and/or "git commit -a”)
Running ‘git status’ will give some insight into what is happening.
Despite trying to merge branches, we still have ‘unmerged paths’.This is a merge conflict and git
status shows the files that have conflicts under ‘Unmerged Paths’.
Git helps in resolving conflicts by adding conflict-resolution markers to the files
that have conflicts, so you can open them manually and resolve those conflicts.
Resolving Conflicts
Your file will contain sections that have markers and the conflicted file will look
something like:
<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@example.com</div>
=======
<div id="footer">
please contact us at support@example.com
</div>
>>>>>>> iss53:index.html
* you can then stage your updated files and commit to complete the merge.
Git show
This command shows you information about a git object - commits, blobs, stashes,
branches etc.
$ git show [<branch_name>] | [<sha>]
Git blame
Show what revision and author last modified each line of a file.The blame command is
a Git feature, designed to help you determine who made changes to a file.
$ git blame <file_name>
* see the git documentation for more options ( http://git-scm.com/book)
Git cherry-pick
Apply the changes introduced by some existing commits.
You’ll often find, when using branches, how easy it is to commit to a different branch (say,
testing branch) than the one intended (master).
$ git cherry-pick testing
[ apply to the current branch the change introduced at the tip of the testing branch ]
$ git cherry-pick testing..hotfix
[ apply to the current branch the changes introduced in ‘hotfix’ that are not in ‘testing’ ]
* see the git documentation for more options ( http://git-scm.com/book)
Git reset
git reset is used to move the tip of the branch to a different commit.This can be used to remove
commits from the current branch.
Recall: when you checkout a branch, it changes HEAD to point to the new branch ref,
populates your Index with the snapshot of that commit, then copies the contents of
the Index into your Working Directory.
file.txt has been modified and the repo is in a clean state.
For instance, if we had our repository as such,
$ git reset —-soft HEAD^
** Reset always moves
what HEAD points to.
That means, from a clean repo, if
we’re on the master branch and
we run git reset 93536a4,
master will point to 9e5e6a4.
$ git reset —-mixed HEAD^
** Reset always moves
what HEAD points to.
That means, from a clean repo, if
we’re on the master branch and
we run git reset —mixed
93536a4, master will point to.

More Related Content

What's hot

A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
Emanuele Olivetti
 
Learning git
Learning gitLearning git
Learning git
Sid Anand
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
Vikram SV
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
Yoad Snapir
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Rueful Robin
 
Git
GitGit
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
Venkat Malladi
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
Behzad Altaf
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
Mohammad Imam Hossain
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
Senthilkumar Gopal
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
Sage Sharp
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
Nilay Binjola
 
Git
GitGit
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
GoogleDevelopersStud1
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Yan Vugenfirer
 
Git & GitHub WorkShop
Git & GitHub WorkShopGit & GitHub WorkShop
Git & GitHub WorkShop
SheilaJimenezMorejon
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
Fran García
 
Git basic
Git basicGit basic
Git basic
Emran Ul Hadi
 

What's hot (20)

A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Learning git
Learning gitLearning git
Learning git
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
Git
GitGit
Git
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Git
GitGit
Git
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git & GitHub WorkShop
Git & GitHub WorkShopGit & GitHub WorkShop
Git & GitHub WorkShop
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
Git basic
Git basicGit basic
Git basic
 

Similar to Git slides

Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
DSC GVP
 
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
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
Hasnaeen Rahman
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Git introduction
Git introductionGit introduction
Git introduction
satyendrajaladi
 
Git and Github - A primer
Git and Github - A primerGit and Github - A primer
Git and Github - A primer
Suryakumar Sudar
 
Git github
Git githubGit github
Git github
Anurag Deb
 
Git 101
Git 101Git 101
Git 101
jayrparro
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
Salvatore Cordiano
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
Gourav Varma
 
Git Developer Cheatsheet
Git Developer CheatsheetGit Developer Cheatsheet
Git Developer CheatsheetAbdul Basit
 
Git for developers
Git for developersGit for developers
Git for developers
Hacen Dadda
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03
Gourav Varma
 
Introduction to Git (part 2)
Introduction to Git (part 2)Introduction to Git (part 2)
Introduction to Git (part 2)
Salvatore Cordiano
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
Manish Chakravarty
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-Bryan
LearningTech
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
mobaires
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 

Similar to Git slides (20)

Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git and Github - A primer
Git and Github - A primerGit and Github - A primer
Git and Github - A primer
 
Git github
Git githubGit github
Git github
 
Git 101
Git 101Git 101
Git 101
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
 
Version controll.pptx
Version controll.pptxVersion controll.pptx
Version controll.pptx
 
Git Developer Cheatsheet
Git Developer CheatsheetGit Developer Cheatsheet
Git Developer Cheatsheet
 
Git for developers
Git for developersGit for developers
Git for developers
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03
 
Introduction to Git (part 2)
Introduction to Git (part 2)Introduction to Git (part 2)
Introduction to Git (part 2)
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-Bryan
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git training
Git trainingGit training
Git training
 

Recently uploaded

ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

Git slides

  • 1.
  • 2. VCS / SCM Source control /Version control is the management of changes to documents, computer programs and other collections of information git is a source code management system.
  • 3. WHAT GIT IS NOT * git is neither Github or Bitbucket
  • 5. DATA REDUNDANCY AND REPLICATION Since there are multiple full repositories on multiple machines (instead of one central repository), the risk of project loss due to server failure or some other catastrophe is much lower. HIGH AVAILABILITY High availability -- Server down? Network down? No problem. Work in your repo (commit, view history, branch, etc) to your heart's content.Try that with Subversion!
  • 6. SUPERIOR DISK UTILIZATION AND NETWORK PERFORMANCE Git efficiently compresses the objects in the .git directory, saving you space. COLLABORATION FRIENDLY Git makes it easy to collaborate on projects with groups of contributors and with great services like Bitbucket, Gitlab and (of course) Github, git's collaboration friendliness is even further magnified.
  • 7. SETUP git config —global user.name “John Doe” git config —global user.email “johndoe@example.co”
  • 8. INITIALIZING A GIT REPO $ git init A git repo is usually a directory that is tracked by git. Git tracks the states of the files in the directory and with various commands, informs you of the status of you repository. To start tracking a directory (to initialize a git repo):
  • 9. The stages of any file in a git repository
  • 10. How git thinks about its data. * One key difference that we need to mention a bit is the way git thinks about data in comparison to how other VCS. Most other systems (CVS, Subversion, Perforce etc.) store information as a list of file-based changes fig: file-based changes
  • 11. * Git thinks of its data more like a set of snapshots of a miniature filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. fig: changes as snapshots
  • 12. Simply put, a branch in Git is a lightweight movable pointer to a commit. Commits are snapshots of your repository.These snapshots usually contain/reference other git object types. COMMITS BRANCHES
  • 13. The image shows how a commit is represented in the repository Pointer to that root tree and all the commit metadata
  • 15. Git status Arguably the most typed command on the git cli, it displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not (yet) tracked by Git (and are not ignored by ‘gitignore’) $ git status
  • 16. Git add In order to begin tracking a new file, you use the command git add. What this command does is to update the ‘index’ using the current content found in the working tree to prepare the content stages for the next commit. $ git add <file_name> Suppose you have a lot of changes in a file and you don’t want to commit all the changes at once: $ git add <file_name> -p The ‘-p’ flag interactively chooses chunks in the file to add to the ‘index’ or staging area.
  • 17. Git commit Stores the current contents of the index in a new commit along with a log message from the user describing the changes. $ git commit If you have changes in the working directory and you really want to add all files with a simple commit message $ git commit —amend To change/update the last commit - in the event that you don’t like the commit message or to add another file to the same commit. $ git commit -am “my super awesome commit message” * Note that any file you have in the index gets added when you use this commit option and yeah, it rewrites history so use carefully.
  • 18. $ git cat-file -p <commit_sha> Since we should now have a commit, lets take a minute to examine it - or any random commit on your system
  • 19. After a few hours of moving bits around and a bunch of commits, our repo ‘kinda’ looks like this *conceptually* Remember: Git thinks of its data more like a set of snapshots of a miniature filesystem
  • 20. *The “master” branch in Git is not a special branch. It is exactly like any other branch.The only reason nearly every repository has one is that the git init command creates it by default and most people don’t bother to change it. Which when looked at from a birds eye view, looks ‘something’ like this:
  • 21. $ git branch testing
  • 22. * By default, the `git branch` command makes the tip of the branch the HEAD Now we have 2 branches pointing to the same commit object f30ab…
  • 23. $ git checkout master $ git branch testing $ git show-ref master $ git show-ref testing Let’s confirm that both branches actually point to the same commit object * We’ll talk a bit about ‘checkout’ soon.
  • 24. Since we’ve seen that a branch is simply a pointer to a commit object - identified by a ‘sha’, it’s fairly easy to select commits as bases for our new branches. $ git branch <branch_name> [<start-point>] (source: man git-branch) Creating a branch with a start point. $ git branch feature/authentication-patch 34ac55…
  • 25. HEAD How does Git know what branch you’re currently on? Easy, It keeps a special pointer called HEAD The HEAD is just a pointer to the currently checked out branch. $ cat .git/HEAD
  • 26. $ git checkout testing * ’checking out’ the testing branch switches HEAD to the testing branch
  • 27. CHECKOUT Git checkout is a very useful command that alters the working tree. Updates files in the working tree to match the version in the index or the specified tree. If no paths are given, git checkout will also update HEAD to set the specified branch as the current branch. It moves HEAD to a different branch (or commit) and updates the working directory to match it. $ git checkout <branch_name>
  • 28. Note that any uncommitted change will be lost during a checkout so Git forces you to stash or commit before checking out to another branch. This is also the reason why when you need to remove the changes made on a file you use: $ git checkout <file_name>
  • 29. Detached HEAD The HEAD becomes ‘detached’ when you checkout to a valid commit that isn’t a branch. $ git checkout 34ac55… This can be used to quickly check inspect an old version of your project. * Being in the ‘detached head’ state can however be dangerous because if you checkout to a grandparent of HEAD for instance and then make commits, you loose being able to get back the commits even after switching to other branches.
  • 31. • Blobs The git “blob” type is just a bunch of bytes that could be anything, like a text file, source code, or a picture, etc. • Trees A git tree is like a filesystem directory.A git tree can point to, or include Git “blob” objects or other git trees. • Commits A git commit object includes: Information about who committed the change/check-in/commit, a pointer to the git tree object that represents the git repository when the commit was done and the parent commit to this commit (so we can easily find out the situation at the previous commit). • Tags A git tag object points to any git commit object. A git tag can be used to refer to a specific tree, rather than having to remember or use the hash of the tree.
  • 32. Inside .git HEAD config description hooks pre-push.sample post-update.sample pre-commit.sample info objects refs [ a text file that is shown as project description in web frontend ] [ repository wide configuration ] [ text file showing currently checked out branch ] [ where git hooks are stored ] * Git hooks are scripts that run automatically every time a particular event occurs in a Git repository [ use this file to ignore files (like .gitignore but isn’t versioned) ]exclude [ Git’s internal warehouse for blobs, indexed by SHAs - where the ’objects’ are stored ] [ Where refs (including) branches live ] heads remotes tags stash [ where your git branches are managed ] [ remote branches ] [ … here be the tags ] [ an ascii text file that has your stash SHAs ]
  • 34. Git clone The git clone command copies an existing Git repository to a new directory. The “working copy” is a full-fledged Git repository—it has its own history, manages its own files, and is a completely isolated environment from the original repository. $ git clone <repo_url> <repo_url> must be a valid ssh, git, ftp or http(s) url
  • 35. …or even on a flash drive $ git clone /<path_to_source> /<new_path> $ git clone /path/to/source/repo /path/on/flash/drive You can clone from and to your local filesystem. * of course, the flash drive should be mounted
  • 36. Git merge The git merge command incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch Say we have a repository with 2 branches as shown below: * see the git documentation for more options ( http://git-scm.com/book)
  • 37. $ git checkout master $ git merge iss53 Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this merge and automatically creates a new commit that points to it. This type of commit referred to as a merge commit, and is special in that it has more than one parent. The above commands leave our repository in a new state. fig: merge commit
  • 38. Merge conflicts Sometimes, the merge between 2 branches may not go smoothly and you’ll have something called a merge conflict. $ git merge iss53 Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result. If your changes on the iss53 branch modified the same part of a file as a new change on the branch being merged unto, you’ll get a merge conflict.
  • 39. $ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a”) Running ‘git status’ will give some insight into what is happening. Despite trying to merge branches, we still have ‘unmerged paths’.This is a merge conflict and git status shows the files that have conflicts under ‘Unmerged Paths’.
  • 40. Git helps in resolving conflicts by adding conflict-resolution markers to the files that have conflicts, so you can open them manually and resolve those conflicts. Resolving Conflicts Your file will contain sections that have markers and the conflicted file will look something like: <<<<<<< HEAD:index.html <div id="footer">contact : email.support@example.com</div> ======= <div id="footer"> please contact us at support@example.com </div> >>>>>>> iss53:index.html * you can then stage your updated files and commit to complete the merge.
  • 41. Git show This command shows you information about a git object - commits, blobs, stashes, branches etc. $ git show [<branch_name>] | [<sha>] Git blame Show what revision and author last modified each line of a file.The blame command is a Git feature, designed to help you determine who made changes to a file. $ git blame <file_name> * see the git documentation for more options ( http://git-scm.com/book)
  • 42. Git cherry-pick Apply the changes introduced by some existing commits. You’ll often find, when using branches, how easy it is to commit to a different branch (say, testing branch) than the one intended (master). $ git cherry-pick testing [ apply to the current branch the change introduced at the tip of the testing branch ] $ git cherry-pick testing..hotfix [ apply to the current branch the changes introduced in ‘hotfix’ that are not in ‘testing’ ] * see the git documentation for more options ( http://git-scm.com/book)
  • 43. Git reset git reset is used to move the tip of the branch to a different commit.This can be used to remove commits from the current branch. Recall: when you checkout a branch, it changes HEAD to point to the new branch ref, populates your Index with the snapshot of that commit, then copies the contents of the Index into your Working Directory. file.txt has been modified and the repo is in a clean state. For instance, if we had our repository as such,
  • 44. $ git reset —-soft HEAD^ ** Reset always moves what HEAD points to. That means, from a clean repo, if we’re on the master branch and we run git reset 93536a4, master will point to 9e5e6a4.
  • 45. $ git reset —-mixed HEAD^ ** Reset always moves what HEAD points to. That means, from a clean repo, if we’re on the master branch and we run git reset —mixed 93536a4, master will point to.