Git

Majid Hajiloo
Majid HajilooSoftware Engineer um Bontech
/mhajiloo
Majid	Hajiloo
WHAT IS VERSION CONTROL?
WHAT IS VERSION CONTROL?
Version control systems are a category of software tools that help a
software team manage changes to source code over time. Version
control software keeps track of every modification to the code in a
special kind of database.
▸ Benefits of version control
A complete long-term change history of every file
Branching and merging
Traceability
3
WHAT IS VERSION CONTROL?
LOCAL VERSION CONTROL SYSTEMS
4
WHAT IS VERSION CONTROL?
CENTRALIZED VERSION CONTROL SYSTEMS
5
WHAT IS VERSION CONTROL?
DISTRIBUTED VERSION CONTROL SYSTEMS
6
WHAT IS GIT?
WHAT IS GIT?
▸ Git was initially designed and
developed in 2005 by Linux kernel
developers (including Linus
Torvalds) for Linux kernel
development.
▸ Having a distributed architecture.
Rather than have only one single
place for the full version history of
the software as is common in once-
popular version control systems
like CVS or Subversion.
8
WHAT IS GIT?
GIT	-	the	stupid	content	tracker	
"git"	can	mean	anything,	depending	on	your	mood.	
	-	random	three-letter	combination	that	is	pronounceable,	and	not	
			actually	used	by	any	common	UNIX	command.		The	fact	that	it	is	a	
			mispronounciation	of	"get"	may	or	may	not	be	relevant.	
	-	stupid.	contemptible	and	despicable.	simple.	Take	your	pick	from	the	
			dictionary	of	slang.	
	-	"global	information	tracker":	you're	in	a	good	mood,	and	it	actually	
			works	for	you.	Angels	sing,	and	a	light	suddenly	fills	the	room.		
	-	"goddamn	idiotic	truckload	of	sh*t":	when	it	breaks	
This	is	a	stupid	(but	extremely	fast)	directory	content	manager.		It	
doesn't	do	a	whole	lot,	but	what	it	_does_	do	is	track	directory	
contents	efficiently.	
9
GIT VS SUBVERSION PERFORMANCESeconds
0
350
700
1050
1400
PUSH/COMMIT PULL/CHECKOUT
GIT SUBVERSION GIT SUBVERSION
39.1
1,334.8
28.5104.5
Commit and checkout times of a repository of 2757 files and 428 directories, summing up to 26MB.
By: http://j.mp/1VY9KIl / CC BY-SA
10
GIT SECURITY
▸ Git has been designed with the integrity of managed
source code as a top priority. The content of the files as
well as the true relationships between files and directories,
versions, tags and commits, all of these objects in the Git
repository are secured with a cryptographically secure
hashing algorithm called SHA1.
▸ Some other version control systems have no protections
against secret alteration at a later date. This can be a
serious information security vulnerability for any
organization that relies on software development.
11
GIT IS A DE FACTO STANDARD
▸ The predominance of Git also means that many third party
software tools and services are already integrated with Git
including IDEs and tools like DVCS desktop clients:
▸ SourceTree (Windows/Mac)
▸ SmartGit (Windows/Linux/Mac)
▸ issue and project tracking software:
▸ JIRA
▸ and code hosting services
▸ GitHub
▸ Bitbucket
12
GIT VS SUBVERSION. GOOGLE TRENDS
Interest over Time (Git vs Subversion)
http://j.mp/23K41sb / Google Trends
13
SETTING UP A REPOSITORY
SETTING UP A REPOSITORY
INSTALLING GIT
▸ Linux: apt-get/yum/dnf/zypper install git
▸ Windows and Mac OS X
https://git-scm.com/downloads
15
SETTING UP A REPOSITORY
git	config
The git	config command lets you configure your Git installation
from the command line. This command can define everything from
user info to preferences to the behavior of a repository.
‣ git	config	--global	user.name	<name>	
‣ git	config	--global	user.email	<email>	
‣ git	config	--global	alias.<alias-name>	<git-command>	
‣ git	config	--system	core.editor	<editor>	
‣ git	config	--list
16
SETTING UP A REPOSITORY
git	init	<directory>
‣ The git init command creates a new Git repository. It can be used
to convert an existing, unversioned project to a Git repository or
initialize a new empty repository. Most of the other Git
commands are not available outside of an initialized repository,
so this is usually the first command you’ll run in a new project.
‣ Executing git init creates a .git subdirectory in the project root,
which contains all of the necessary metadata for the repo. Aside
from the .git directory, an existing project remains unaltered
(unlike SVN, Git doesn't require a .git folder in every
subdirectory).
17
SETTING UP A REPOSITORY
git	clone	<repo>
‣ The git	clone command copies an existing Git repository. This
is sort of like svn	checkout, except 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.
‣ The original repository can be located on the local filesystem or
on a remote machine accessible via HTTP or SSH.
18
SAVING CHANGES
19
SAVING CHANGES - SNAPSHOTS, NOT DIFFERENCES 20
SAVING CHANGES - SNAPSHOTS, NOT DIFFERENCES
Storing data as changes to a base version of each file
Storing data as snapshots of the project over time
20
SAVING CHANGES - THE THREE STATES
▸ Committed
Committed means that the data is safely stored in your
local database.
▸ Modified
Modified means that you have changed the file but have
not committed it to your database yet.
▸ Staged
Staged means that you have marked a modified file in
its current version to go into your next commit snapshot.
21
SAVING CHANGES - THE THREE STATES
Working directory, staging area, and Git directory
22
SAVING CHANGES
git	add	<file/directory/.>
‣ The git	add command adds a change in the working directory
to the staging area. It tells Git that you want to include updates
to a particular file in the next commit. However, git add doesn't
really affect the repository in any significant way—changes are
not actually recorded until you run git	commit.
‣ In conjunction with these commands, you'll also need git	
status to view the state of the working directory and the staging
area.
23
SAVING CHANGES - CHECKING THE STATUS OF YOUR FILES
$	git	status	
On	branch	master	
Your	branch	is	up-to-date	with	'origin/master'.	
nothing	to	commit,	working	directory	clean
24
SAVING CHANGES - CHECKING THE STATUS OF YOUR FILES
$	echo	'My	Project'	>	README	
$	git	status	
On	branch	master	
Your	branch	is	up-to-date	with	'origin/master'.	
Untracked	files:	
		(use	"git	add	<file>..."	to	include	in	what	will	
be	committed)	
				README	
nothing	added	to	commit	but	untracked	files	present	
(use	"git	add"	to	track)
25
SAVING CHANGES - CHECKING THE STATUS OF YOUR FILES
$	git	add	README	
$	git	status	
On	branch	master	
Your	branch	is	up-to-date	with	'origin/master'.	
Changes	to	be	committed:	
		(use	"git	reset	HEAD	<file>..."	to	unstage)	
				new	file:			README
26
SAVING CHANGES
IGNORING FILES
▸ From time to time, there are files you don't want Git to
check in.
▸ If you create a file in your repository named .gitignore, Git
uses it to determine which files and directories to ignore,
before you make a commit.
$	cat	.gitignore	
*.[oa]	
log/*.log
27
SAVING CHANGES
git	commit
The git	 commit	 command commits the staged snapshot to the
local repository. Git will never change them unless you explicity
ask it to. Along with git add, this is one of the most important Git
commands. This command is nothing like svn commit.
$	git	commit	-m	"Story	182:	Fix	benchmarks	for	speed"	
[master	463dc4f]	Story	182:	Fix	benchmarks	for	speed	
	2	files	changed,	2	insertions(+)	
	create	mode	100644	README
28
SAVING CHANGES
A commit and its tree
29
SAVING CHANGES
git	checkout
The git	 checkout command serves three distinct functions:
checking out files, checking out commits, and checking out
branches
$	git	checkout	<branch>	
$	git	checkout	<commit>	<file>	
$	git	checkout	<commit>
30
SAVING CHANGES
git	revert	<commit>
The git	 revert command undoes a committed snapshot. But,
instead of removing the commit from the project history, it figures
out how to undo the changes introduced by the commit and
appends a new commit with the resulting content.
31
SAVING CHANGES
git	revert	<commit>
The git	 revert command undoes a committed snapshot. But,
instead of removing the commit from the project history, it figures
out how to undo the changes introduced by the commit and
appends a new commit with the resulting content.
ResettingReverting
31
SYNCING
git	fetch	<remote>	<branch>
‣ The git fetch command imports commits from a remote
repository into your local repo. The resulting commits are stored
as remote branches instead of the normal local branches that
we’ve been working with.
‣ Fetching is what you do when you want to see what everybody
else has been working on. Since fetched content is represented
as a remote branch, it has absolutely no effect on your local
development work.
32
SYNCING
git	pull	<remote>
‣ Merging upstream changes into your local repository is a
common task in Git-based collaboration workflows.
‣ You can think of git	pull as Git's version of svn	update. It’s an
easy way to synchronize your local repository with upstream
changes.
33
SYNCING - PULL 34
SYNCING - PULL 34
SYNCING - PULL 34
SYNCING
git	push	<remote>	<branch>
‣ Pushing is how you transfer commits from your local repository
to a remote repo. It's the counterpart to git	fetch, but whereas
fetching imports commits to local branches, pushing exports
commits to remote branches.
‣ After you’ve accumulated several local commits and are ready to
share them with the rest of the team
35
SYNCING
git	tag	-a	<tag>
‣ Like most VCSs, Git has the ability to tag specific points in history
as being important. Typically people use this functionality to
mark release points (v1.0, and so on).
‣ Git uses two main types of tags: lightweight and annotated.
36
SYNCING 37
USING BRANCHES
USING BRANCHES
git	branch
‣ In Git, branches are a part of your everyday development
process. When you want to add a new feature or fix a bug—no
matter how big or how small—you spawn a new branch to
encapsulate your changes. This makes sure that unstable code is
never committed to the main code base
‣ A branch represents an independent line of development.
Branches serve as an abstraction for the edit/stage/commit.
‣ The git branch command lets you create, list, rename, and delete
branches
39
USING BRANCHES 40
$	git	branch	crazy-experiment
USING BRANCHES 40
$	git	branch	crazy-experiment
USING BRANCHES
git	merge	<branch>
‣ Merging is Git's way of putting a forked history back together
again.
‣ The git	merge command lets you take the independent lines of
development created by git	branch and integrate them into a
single branch.
41
USING BRANCHES
git	merge	<branch>
42
COMPARING WORKFLOWS
COMPARING WORKFLOWS
CENTRALIZED WORKFLOW
44
Like Subversion, the Centralized
Workflow uses a central
repository to serve as the single
point-of-entry for all changes to
the project. Instead of trunk, the
default development branch is
called master and all changes
are committed into this branch.
This workflow doesn’t require
any other branches besides
master
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
SOMEONE INITIALIZES THE CENTRAL REPOSITORY
45
$	ssh	user@host	git	init	--bare	/path/to/repo.git
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
EVERYBODY CLONES THE CENTRAL REPOSITORY
46
$	git	clone	ssh://user@host/path/to/repo.git
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
JOHN AND MARY WORK ON THEIR FEATURES
47
$	git	status	#	View	the	state	of	the	repo	
$	git	add	<some-file>	#	Stage	a	file	
$	git	commit	#	Commit	a	file</some-file>
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
JOHN AND MARY WORK ON THEIR FEATURES
47
$	git	push	origin	master
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY TRIES TO PUBLISH HER FEATURE
48
$	git	push	origin	master
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY TRIES TO PUBLISH HER FEATURE
48
$	git	push	origin	master
error:	failed	to	push	some	refs	to	'/path/to/repo.git'	
hint:	Updates	were	rejected	because	the	tip	of	your	
current	branch	is	behind	
hint:	its	remote	counterpart.	Merge	the	remote	changes	
(e.g.	'git	pull')	
hint:	before	pushing	again.	
hint:	See	the	'Note	about	fast-forwards'	in	'git	push	
--help'	for	details.
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY REBASES ON TOP OF JOHN’S COMMIT(S)
49
$	git	pull	--rebase	origin	master
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY REBASES ON TOP OF JOHN’S COMMIT(S)
49
$	git	pull	--rebase	origin	master
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY RESOLVES A MERGE CONFLICT
50
CONFLICT	(content):	Merge	conflict	in	<some-file>
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY RESOLVES A MERGE CONFLICT
51
$	git	status
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY RESOLVES A MERGE CONFLICT
51
$	git	status
#	Unmerged	paths:	
#	(use	"git	reset	HEAD	<some-file>..."	to	unstage)	
#	(use	"git	add/rm	<some-file>..."	as	appropriate	to	
mark	resolution)	
#	
#	both	modified:	<some-file>
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY RESOLVES A MERGE CONFLICT
52
#!	/usr/bin/env	ruby	
def	hello	
<<<<<<<	HEAD	
		puts	'hola	world'	
=======	
		puts	'hello	mundo'	
>>>>>>>	master	
end	
hello()
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY RESOLVES A MERGE CONFLICT
52
#!	/usr/bin/env	ruby	
def	hello	
		puts	'hola	world'	
end	
hello()
$	git	add	<some-file>	
$	git	rebase	--continue
$	git	rebase	--abort
COMPARING WORKFLOWS - CENTRALIZED WORKFLOW
MARY SUCCESSFULLY PUBLISHES HER FEATURE
53
$	git	push	origin	master
COMPARING WORKFLOWS
FEATURE BRANCH WORKFLOW
54
The core idea behind the Feature
Branch Workflow is that all feature
development should take place in a
dedicated branch instead of the
master branch. This encapsulation
makes it easy for multiple developers
to work on a particular feature
without disturbing the main
codebase. It also means the master
branch will never contain broken
code, which is a huge advantage for
c o n t i n u o u s i n t e g r a t i o n
environments.
COMPARING WORKFLOWS - FEATURE BRANCH WORKFLOW
MARY BEGINS A NEW FEATURE
55
$	git	checkout	-b	marys-feature	master	
$	git	status	
$	git	add	<some-file>	
$	git	commit
COMPARING WORKFLOWS - FEATURE BRANCH WORKFLOW
MARY MAKES THE CHANGES
56
$	git	push	-u	origin	marys-feature
COMPARING WORKFLOWS - FEATURE BRANCH WORKFLOW
MARY PUBLISHES HER FEATURE
57
$	git	checkout	master	
$	git	pull	
$	git	pull	origin	marys-feature	
$	git	push
COMPARING WORKFLOWS
GITFLOW WORKFLOW
58
The Gitflow Workflow defines a strict
branching model designed around
the project release. While somewhat
more complicated than the Feature
Branch Workflow, this provides a
robust framework for managing
larger projects. This workflow doesn’t
add any new concepts or commands
beyond what’s required for the
Feature Branch Workflow. Instead, it
assigns very specific roles to different
branches and defines how and when
they should interact.
by Vincent Driessen | http://j.mp/1YLriqr
COMPARING WORKFLOWS - GITFLOW WORKFLOW
HISTORICAL BRANCHES
59
The master branch stores the official release history, and the
develop branch serves as an integration branch for features.
COMPARING WORKFLOWS - GITFLOW WORKFLOW
FEATURE BRANCHES
60
Each new feature instead of branching off of master, feature
branches use develop as their parent branch
COMPARING WORKFLOWS - GITFLOW WORKFLOW
FEATURE BRANCHES
61
May branch off from:
‣ develop
Must merge back into:
‣ develop
Branch naming convention:
‣ anything except master, develop, release-*, or hotfix-*
COMPARING WORKFLOWS - GITFLOW WORKFLOW
RELEASE BRANCHES
62
Once develop has acquired enough features for a release, you
fork a release branch off of develop.
COMPARING WORKFLOWS - GITFLOW WORKFLOW
RELEASE BRANCHES
63
May branch off from:
‣ develop
Must merge back into:
‣ develop and master
Branch naming convention:
‣ release-*
COMPARING WORKFLOWS - GITFLOW WORKFLOW
MAINTENANCE BRANCHES
64
Maintenance or “hotfix” branches are used to quickly patch production
releases. This is the only branch that should fork directly off of master.
COMPARING WORKFLOWS - GITFLOW WORKFLOW
MAINTENANCE BRANCHES
65
May branch off from:
‣ master
Must merge back into:
‣ develop and master
Branch naming convention:
‣ hotfix-*
SVN TO GIT
SVN TO GIT 67
http://john.albin.net/git/convert-subversion-to-git
1. Retrieve a list of all Subversion committers.
2. Clone the Subversion repository using git-svn.
3. Convert svn:ignore properties to .gitignore.
4. Push repository to a bare git repository.
5. Rename “trunk” branch to “master”
6. Clean up branches and tags.
7. Drink.
GUI CLIENTS
GUI CLIENTS
SOURCETREE
69
Platforms: Mac, Windows | Price: Free
GUI CLIENTS
SMARTGIT
70
Platforms: Windows, Mac, Linux | Price: $79/user / Free for non-commercial use
GUI CLIENTS 71
https://git-scm.com/downloads/guis
The END
1 von 82

Recomendados

Version Control with Git von
Version Control with GitVersion Control with Git
Version Control with GitLuigi De Russis
1.1K views62 Folien
Starting with Git & GitHub von
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHubNicolás Tourné
10.7K views35 Folien
Git training von
Git trainingGit training
Git trainingadm_exoplatform
4.1K views37 Folien
Git Introduction Tutorial von
Git Introduction TutorialGit Introduction Tutorial
Git Introduction TutorialThomas Rausch
3.9K views148 Folien
Git 101 von
Git 101Git 101
Git 101jayrparro
2.2K views20 Folien
Version control system von
Version control systemVersion control system
Version control systemAndrew Liu
1.5K views48 Folien

Más contenido relacionado

Was ist angesagt?

Git and Github von
Git and GithubGit and Github
Git and GithubWen-Tien Chang
15.7K views117 Folien
Git introduction von
Git introductionGit introduction
Git introductionsatyendrajaladi
938 views33 Folien
Git One Day Training Notes von
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
3.5K views67 Folien
Git tutorial von
Git tutorialGit tutorial
Git tutorialElli Kanal
4.8K views63 Folien
Git Tutorial I von
Git Tutorial IGit Tutorial I
Git Tutorial IJim Yeh
1.2K views39 Folien
Advanced Git Tutorial von
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
11.7K views42 Folien

Was ist angesagt?(20)

Git One Day Training Notes von glen_a_smith
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith3.5K views
Git tutorial von Elli Kanal
Git tutorialGit tutorial
Git tutorial
Elli Kanal4.8K views
Git Tutorial I von Jim Yeh
Git Tutorial IGit Tutorial I
Git Tutorial I
Jim Yeh1.2K views
Advanced Git Tutorial von Sage Sharp
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
Sage Sharp11.7K views
Introducing Git and git flow von Sebin Benjamin
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
Sebin Benjamin127 views
Introduction to Git, DrupalCamp LA 2015 von mwrather
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015
mwrather516 views
Version Control & Git von Jason Byrne
Version Control & GitVersion Control & Git
Version Control & Git
Jason Byrne1.2K views
GitLab as an Alternative Development Platform for Github.com von B1 Systems GmbH
GitLab as an Alternative Development Platform for Github.comGitLab as an Alternative Development Platform for Github.com
GitLab as an Alternative Development Platform for Github.com
B1 Systems GmbH1.5K views
Introduction to Git and Github von Max Claus Nunes
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes1.8K views
Introduction to Git and Github - Google Developer Student Clubs CET, Trivandrum von AbhijitNarayan2
Introduction to Git and Github - Google Developer Student Clubs CET, TrivandrumIntroduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
AbhijitNarayan2215 views
Git Terminologies von Yash
Git TerminologiesGit Terminologies
Git Terminologies
Yash 125 views
Git Introduction von Gareth Hall
Git IntroductionGit Introduction
Git Introduction
Gareth Hall1.3K views
Git and github - Verson Control for the Modern Developer von John Stevenson
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern Developer
John Stevenson1.7K views

Destacado

Git Basic von
Git BasicGit Basic
Git BasicLuke Luo
1.5K views120 Folien
Using Git von
Using GitUsing Git
Using GitAbayomi Ayoola
930 views35 Folien
GIT_In_90_Minutes von
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutesvimukthirandika
785 views65 Folien
Devoxx France 2015 - Se préparer à l'arrivée d'Angular 2 von
Devoxx France 2015 - Se préparer à l'arrivée d'Angular 2Devoxx France 2015 - Se préparer à l'arrivée d'Angular 2
Devoxx France 2015 - Se préparer à l'arrivée d'Angular 2Romain Linsolas
7K views22 Folien
Tutoriel GIT von
Tutoriel GITTutoriel GIT
Tutoriel GITFrancois ANDRE
3.3K views83 Folien
Git Flow: un processus de développement Agile von
Git Flow: un processus de développement AgileGit Flow: un processus de développement Agile
Git Flow: un processus de développement AgileXavier Hausherr
13.9K views35 Folien

Similar a Git

Git and Github von
Git and GithubGit and Github
Git and GithubTeodora Ahkozidou
103 views32 Folien
Presentation on Repository Control System von
Presentation on Repository Control SystemPresentation on Repository Control System
Presentation on Repository Control SystemMd. Mujahid Islam
409 views34 Folien
Git and github von
Git and githubGit and github
Git and githubTeodora Ahkozidou
139 views32 Folien
Git Commands Every Developer Should Know? von
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
138 views67 Folien
git github PPT_GDSCIIITK.pptx von
git github PPT_GDSCIIITK.pptxgit github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxAbelPhilipJoseph
32 views31 Folien
Introduction to GitHub, Open Source and Tech Article von
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticlePRIYATHAMDARISI
224 views58 Folien

Similar a Git(20)

Git Commands Every Developer Should Know? von 9 series
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
9 series138 views
Introduction to GitHub, Open Source and Tech Article von PRIYATHAMDARISI
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech Article
PRIYATHAMDARISI224 views
Introduction to Git & GitHub von Wasit Shafi
Introduction to Git & GitHubIntroduction to Git & GitHub
Introduction to Git & GitHub
Wasit Shafi19 views
Hacktoberfest intro to Git and GitHub von DSC GVP
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
DSC GVP149 views
Git for developers von Hacen Dadda
Git for developersGit for developers
Git for developers
Hacen Dadda214 views
Rc094 010d-git 2 - desconocido von Luis Bertel
Rc094 010d-git 2 - desconocidoRc094 010d-git 2 - desconocido
Rc094 010d-git 2 - desconocido
Luis Bertel1.7K views
introduction in version control system von Biga Gaber
introduction in version control systemintroduction in version control system
introduction in version control system
Biga Gaber359 views

Último

Zero to Automated in Under a Year von
Zero to Automated in Under a YearZero to Automated in Under a Year
Zero to Automated in Under a YearNetwork Automation Forum
15 views23 Folien
Melek BEN MAHMOUD.pdf von
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
14 views1 Folie
PRODUCT LISTING.pptx von
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 Folie
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive von
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
31 views35 Folien
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 von
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
52 views8 Folien
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors von
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
19 views15 Folien

Último(20)

Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive von Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 von IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors von sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... von Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views
Unit 1_Lecture 2_Physical Design of IoT.pdf von StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 von Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi127 views
HTTP headers that make your website go faster - devs.gent November 2023 von Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
Data Integrity for Banking and Financial Services von Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely21 views
6g - REPORT.pdf von Liveplex
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdf
Liveplex10 views
Piloting & Scaling Successfully With Microsoft Viva von Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Five Things You SHOULD Know About Postman von Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 views
Business Analyst Series 2023 - Week 3 Session 5 von DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10248 views

Git

  • 2. WHAT IS VERSION CONTROL?
  • 3. WHAT IS VERSION CONTROL? Version control systems are a category of software tools that help a software team manage changes to source code over time. Version control software keeps track of every modification to the code in a special kind of database. ▸ Benefits of version control A complete long-term change history of every file Branching and merging Traceability 3
  • 4. WHAT IS VERSION CONTROL? LOCAL VERSION CONTROL SYSTEMS 4
  • 5. WHAT IS VERSION CONTROL? CENTRALIZED VERSION CONTROL SYSTEMS 5
  • 6. WHAT IS VERSION CONTROL? DISTRIBUTED VERSION CONTROL SYSTEMS 6
  • 8. WHAT IS GIT? ▸ Git was initially designed and developed in 2005 by Linux kernel developers (including Linus Torvalds) for Linux kernel development. ▸ Having a distributed architecture. Rather than have only one single place for the full version history of the software as is common in once- popular version control systems like CVS or Subversion. 8
  • 10. GIT VS SUBVERSION PERFORMANCESeconds 0 350 700 1050 1400 PUSH/COMMIT PULL/CHECKOUT GIT SUBVERSION GIT SUBVERSION 39.1 1,334.8 28.5104.5 Commit and checkout times of a repository of 2757 files and 428 directories, summing up to 26MB. By: http://j.mp/1VY9KIl / CC BY-SA 10
  • 11. GIT SECURITY ▸ Git has been designed with the integrity of managed source code as a top priority. The content of the files as well as the true relationships between files and directories, versions, tags and commits, all of these objects in the Git repository are secured with a cryptographically secure hashing algorithm called SHA1. ▸ Some other version control systems have no protections against secret alteration at a later date. This can be a serious information security vulnerability for any organization that relies on software development. 11
  • 12. GIT IS A DE FACTO STANDARD ▸ The predominance of Git also means that many third party software tools and services are already integrated with Git including IDEs and tools like DVCS desktop clients: ▸ SourceTree (Windows/Mac) ▸ SmartGit (Windows/Linux/Mac) ▸ issue and project tracking software: ▸ JIRA ▸ and code hosting services ▸ GitHub ▸ Bitbucket 12
  • 13. GIT VS SUBVERSION. GOOGLE TRENDS Interest over Time (Git vs Subversion) http://j.mp/23K41sb / Google Trends 13
  • 15. SETTING UP A REPOSITORY INSTALLING GIT ▸ Linux: apt-get/yum/dnf/zypper install git ▸ Windows and Mac OS X https://git-scm.com/downloads 15
  • 16. SETTING UP A REPOSITORY git config The git config command lets you configure your Git installation from the command line. This command can define everything from user info to preferences to the behavior of a repository. ‣ git config --global user.name <name> ‣ git config --global user.email <email> ‣ git config --global alias.<alias-name> <git-command> ‣ git config --system core.editor <editor> ‣ git config --list 16
  • 17. SETTING UP A REPOSITORY git init <directory> ‣ The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new empty repository. Most of the other Git commands are not available outside of an initialized repository, so this is usually the first command you’ll run in a new project. ‣ Executing git init creates a .git subdirectory in the project root, which contains all of the necessary metadata for the repo. Aside from the .git directory, an existing project remains unaltered (unlike SVN, Git doesn't require a .git folder in every subdirectory). 17
  • 18. SETTING UP A REPOSITORY git clone <repo> ‣ The git clone command copies an existing Git repository. This is sort of like svn checkout, except 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. ‣ The original repository can be located on the local filesystem or on a remote machine accessible via HTTP or SSH. 18
  • 20. SAVING CHANGES - SNAPSHOTS, NOT DIFFERENCES 20
  • 21. SAVING CHANGES - SNAPSHOTS, NOT DIFFERENCES Storing data as changes to a base version of each file Storing data as snapshots of the project over time 20
  • 22. SAVING CHANGES - THE THREE STATES ▸ Committed Committed means that the data is safely stored in your local database. ▸ Modified Modified means that you have changed the file but have not committed it to your database yet. ▸ Staged Staged means that you have marked a modified file in its current version to go into your next commit snapshot. 21
  • 23. SAVING CHANGES - THE THREE STATES Working directory, staging area, and Git directory 22
  • 24. SAVING CHANGES git add <file/directory/.> ‣ The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit. ‣ In conjunction with these commands, you'll also need git status to view the state of the working directory and the staging area. 23
  • 25. SAVING CHANGES - CHECKING THE STATUS OF YOUR FILES $ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean 24
  • 26. SAVING CHANGES - CHECKING THE STATUS OF YOUR FILES $ echo 'My Project' > README $ git status On branch master Your branch is up-to-date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) README nothing added to commit but untracked files present (use "git add" to track) 25
  • 27. SAVING CHANGES - CHECKING THE STATUS OF YOUR FILES $ git add README $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: README 26
  • 28. SAVING CHANGES IGNORING FILES ▸ From time to time, there are files you don't want Git to check in. ▸ If you create a file in your repository named .gitignore, Git uses it to determine which files and directories to ignore, before you make a commit. $ cat .gitignore *.[oa] log/*.log 27
  • 29. SAVING CHANGES git commit The git commit command commits the staged snapshot to the local repository. Git will never change them unless you explicity ask it to. Along with git add, this is one of the most important Git commands. This command is nothing like svn commit. $ git commit -m "Story 182: Fix benchmarks for speed" [master 463dc4f] Story 182: Fix benchmarks for speed 2 files changed, 2 insertions(+) create mode 100644 README 28
  • 30. SAVING CHANGES A commit and its tree 29
  • 31. SAVING CHANGES git checkout The git checkout command serves three distinct functions: checking out files, checking out commits, and checking out branches $ git checkout <branch> $ git checkout <commit> <file> $ git checkout <commit> 30
  • 32. SAVING CHANGES git revert <commit> The git revert command undoes a committed snapshot. But, instead of removing the commit from the project history, it figures out how to undo the changes introduced by the commit and appends a new commit with the resulting content. 31
  • 33. SAVING CHANGES git revert <commit> The git revert command undoes a committed snapshot. But, instead of removing the commit from the project history, it figures out how to undo the changes introduced by the commit and appends a new commit with the resulting content. ResettingReverting 31
  • 34. SYNCING git fetch <remote> <branch> ‣ The git fetch command imports commits from a remote repository into your local repo. The resulting commits are stored as remote branches instead of the normal local branches that we’ve been working with. ‣ Fetching is what you do when you want to see what everybody else has been working on. Since fetched content is represented as a remote branch, it has absolutely no effect on your local development work. 32
  • 35. SYNCING git pull <remote> ‣ Merging upstream changes into your local repository is a common task in Git-based collaboration workflows. ‣ You can think of git pull as Git's version of svn update. It’s an easy way to synchronize your local repository with upstream changes. 33
  • 39. SYNCING git push <remote> <branch> ‣ Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch, but whereas fetching imports commits to local branches, pushing exports commits to remote branches. ‣ After you’ve accumulated several local commits and are ready to share them with the rest of the team 35
  • 40. SYNCING git tag -a <tag> ‣ Like most VCSs, Git has the ability to tag specific points in history as being important. Typically people use this functionality to mark release points (v1.0, and so on). ‣ Git uses two main types of tags: lightweight and annotated. 36
  • 43. USING BRANCHES git branch ‣ In Git, branches are a part of your everyday development process. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes. This makes sure that unstable code is never committed to the main code base ‣ A branch represents an independent line of development. Branches serve as an abstraction for the edit/stage/commit. ‣ The git branch command lets you create, list, rename, and delete branches 39
  • 46. USING BRANCHES git merge <branch> ‣ Merging is Git's way of putting a forked history back together again. ‣ The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. 41
  • 49. COMPARING WORKFLOWS CENTRALIZED WORKFLOW 44 Like Subversion, the Centralized Workflow uses a central repository to serve as the single point-of-entry for all changes to the project. Instead of trunk, the default development branch is called master and all changes are committed into this branch. This workflow doesn’t require any other branches besides master
  • 50. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW SOMEONE INITIALIZES THE CENTRAL REPOSITORY 45 $ ssh user@host git init --bare /path/to/repo.git
  • 51. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW EVERYBODY CLONES THE CENTRAL REPOSITORY 46 $ git clone ssh://user@host/path/to/repo.git
  • 52. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW JOHN AND MARY WORK ON THEIR FEATURES 47 $ git status # View the state of the repo $ git add <some-file> # Stage a file $ git commit # Commit a file</some-file>
  • 53. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW JOHN AND MARY WORK ON THEIR FEATURES 47 $ git push origin master
  • 54. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY TRIES TO PUBLISH HER FEATURE 48 $ git push origin master
  • 55. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY TRIES TO PUBLISH HER FEATURE 48 $ git push origin master error: failed to push some refs to '/path/to/repo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 56. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY REBASES ON TOP OF JOHN’S COMMIT(S) 49 $ git pull --rebase origin master
  • 57. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY REBASES ON TOP OF JOHN’S COMMIT(S) 49 $ git pull --rebase origin master
  • 58. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY RESOLVES A MERGE CONFLICT 50 CONFLICT (content): Merge conflict in <some-file>
  • 59. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY RESOLVES A MERGE CONFLICT 51 $ git status
  • 60. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY RESOLVES A MERGE CONFLICT 51 $ git status # Unmerged paths: # (use "git reset HEAD <some-file>..." to unstage) # (use "git add/rm <some-file>..." as appropriate to mark resolution) # # both modified: <some-file>
  • 61. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY RESOLVES A MERGE CONFLICT 52 #! /usr/bin/env ruby def hello <<<<<<< HEAD puts 'hola world' ======= puts 'hello mundo' >>>>>>> master end hello()
  • 62. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY RESOLVES A MERGE CONFLICT 52 #! /usr/bin/env ruby def hello puts 'hola world' end hello() $ git add <some-file> $ git rebase --continue $ git rebase --abort
  • 63. COMPARING WORKFLOWS - CENTRALIZED WORKFLOW MARY SUCCESSFULLY PUBLISHES HER FEATURE 53 $ git push origin master
  • 64. COMPARING WORKFLOWS FEATURE BRANCH WORKFLOW 54 The core idea behind the Feature Branch Workflow is that all feature development should take place in a dedicated branch instead of the master branch. This encapsulation makes it easy for multiple developers to work on a particular feature without disturbing the main codebase. It also means the master branch will never contain broken code, which is a huge advantage for c o n t i n u o u s i n t e g r a t i o n environments.
  • 65. COMPARING WORKFLOWS - FEATURE BRANCH WORKFLOW MARY BEGINS A NEW FEATURE 55 $ git checkout -b marys-feature master $ git status $ git add <some-file> $ git commit
  • 66. COMPARING WORKFLOWS - FEATURE BRANCH WORKFLOW MARY MAKES THE CHANGES 56 $ git push -u origin marys-feature
  • 67. COMPARING WORKFLOWS - FEATURE BRANCH WORKFLOW MARY PUBLISHES HER FEATURE 57 $ git checkout master $ git pull $ git pull origin marys-feature $ git push
  • 68. COMPARING WORKFLOWS GITFLOW WORKFLOW 58 The Gitflow Workflow defines a strict branching model designed around the project release. While somewhat more complicated than the Feature Branch Workflow, this provides a robust framework for managing larger projects. This workflow doesn’t add any new concepts or commands beyond what’s required for the Feature Branch Workflow. Instead, it assigns very specific roles to different branches and defines how and when they should interact. by Vincent Driessen | http://j.mp/1YLriqr
  • 69. COMPARING WORKFLOWS - GITFLOW WORKFLOW HISTORICAL BRANCHES 59 The master branch stores the official release history, and the develop branch serves as an integration branch for features.
  • 70. COMPARING WORKFLOWS - GITFLOW WORKFLOW FEATURE BRANCHES 60 Each new feature instead of branching off of master, feature branches use develop as their parent branch
  • 71. COMPARING WORKFLOWS - GITFLOW WORKFLOW FEATURE BRANCHES 61 May branch off from: ‣ develop Must merge back into: ‣ develop Branch naming convention: ‣ anything except master, develop, release-*, or hotfix-*
  • 72. COMPARING WORKFLOWS - GITFLOW WORKFLOW RELEASE BRANCHES 62 Once develop has acquired enough features for a release, you fork a release branch off of develop.
  • 73. COMPARING WORKFLOWS - GITFLOW WORKFLOW RELEASE BRANCHES 63 May branch off from: ‣ develop Must merge back into: ‣ develop and master Branch naming convention: ‣ release-*
  • 74. COMPARING WORKFLOWS - GITFLOW WORKFLOW MAINTENANCE BRANCHES 64 Maintenance or “hotfix” branches are used to quickly patch production releases. This is the only branch that should fork directly off of master.
  • 75. COMPARING WORKFLOWS - GITFLOW WORKFLOW MAINTENANCE BRANCHES 65 May branch off from: ‣ master Must merge back into: ‣ develop and master Branch naming convention: ‣ hotfix-*
  • 77. SVN TO GIT 67 http://john.albin.net/git/convert-subversion-to-git 1. Retrieve a list of all Subversion committers. 2. Clone the Subversion repository using git-svn. 3. Convert svn:ignore properties to .gitignore. 4. Push repository to a bare git repository. 5. Rename “trunk” branch to “master” 6. Clean up branches and tags. 7. Drink.
  • 80. GUI CLIENTS SMARTGIT 70 Platforms: Windows, Mac, Linux | Price: $79/user / Free for non-commercial use