SlideShare une entreprise Scribd logo
1  sur  69
Télécharger pour lire hors ligne
A Practical Introduction to git
Emanuele Olivetti
NeuroInformatics Laboratory (NILab)
Bruno Kessler Foundation (FBK), Trento, Italy
Center for Mind and Brain Sciences (CIMeC), University of Trento, Italy
http://nilab.fbk.eu
olivetti@fbk.eu
1 / 69
Outline
Version Control: git.
Scenario 1: single developer, local repository.
Demo single+local
Scenario 2: Team of developers, central remote
repository. Minimalistic.
Demo multi+remote
Branching.
Scenario 3: Contributing to a Software Project hosted on
GitHub.
Extras: how to set up centralised repository, and more.
2 / 69
Version Control: Naming & Meaning
Wikipedia
“Revision control, also known as version control, source control
or software configuration management (SCM), is the
management of changes to documents, programs, and other
information stored as computer files.”
Popular Acronyms:
VC
SCM
Misnomer:
Versioning
Q: have you ever used VC? (raise your hand = YES)
3 / 69
Version Control: Local, Centralized, Distributed
From Pro Git, S.Chacon 2009, CC 3.0 license.
4 / 69
Survey: git
Q1: Have you heard about git?
Q2: Do you use git?
Q3: Why the “git” name? (from git FAQ)
1 Random three-letter combination that is pronounceable.
2 Acronym (global information tracker).
3 Irony.
5 / 69
git? Why “git”?
Linus Torvalds: “I name all
my projects after myself.
First Linux, now git.”
http://www.merriam-webster.
com/dictionary/git
6 / 69
git
git
usage: git [OPTIONS] COMMAND [ARGS]
The most commonly used git commands are:
add Add file contents to the index
commit Record changes to the repository
diff Show changes between commits, commit a
...
git help <command>
git status
7 / 69
git
Introduce yourself to git:
git config --global user.name "Emanuele Olivetti"
git config --global user.email "olivetti@fbk.eu"
8 / 69
git. Single developer + local repository.
Scenario 1: single developer + local repository.
9 / 69
Single+Local git. Motivations.
Q: do you use VC for local repo?
Why VC for single developer + local repository?
First step towards a shared project.
Backup.
To keep the memory of your work.
10 / 69
Single+Local git. Init.
git init
Creates an empty git repository.
Creates the git directory: .git/
working
directory
staging
area
master
Note: it is safe. It does not change your pre-existing files.
11 / 69
Single+Local git. The tracking process.
git add <filename>
working directory
staging area
master
git add
git commit
git commit -m "Let us begin."
Wikipedia
“A staging area is a location where organisms, people,
vehicles, equipment or material are assembled before use”.
12 / 69
Single+Local git. Add.
git add file1 [file2 ...]
Adds new files for next commit.
Adds content from working dir to the staging area (index)
for next commit.
DOES NOT add info on file permissions other than
exec/noexec (755 / 644).
DOES not add directories per se.
working
directory
staging
area
master
git add
13 / 69
Single+Local git. Commit.
git commit [-m "Commit message."]
Records changes from the staging area to master.
working
directory
staging
area
master
git commit
14 / 69
Single+Local git. Commit.
git commit file1 file2
Records all changes of file1, file2 from working dir and
staging area to master.
working
directory
staging
area
master
git commit <filename>
git commit -a
Records all changes in working dir and staging area. Be
Careful!
15 / 69
Single+Local git. Commit names. OPTIONAL
Every commit is a git-object.
The history of a project is a graph of objects referenced by
a 40-digit git-name: SHA1(object).
SHA1(object) = 160-bit Secure Hash Algorithm.
Examples:
$ git commit README -m "Added README."
[master dbb4929] Added README.
1 files changed, 1 insertions(+), ...
or
$ git log
commit dbb49293790b84f0bdcd74fd9fa5cab0...
Author: Emanuele Olivetti <olivetti@fbk.eu>
Date: Wed Sep 15 00:08:46 2010 +0200
...
16 / 69
Single+Local git. Diff.
git diff
Shows what changes between working directory and staging
area (index).
working
directory
staging
area
master
git diff
17 / 69
Single+Local git. Diff. OPTIONAL
Q: “git add” then “git diff”. What output?
git diff --cached shows differences between index and
last commit (HEAD).
working
directory
staging
area
master
git diff --cached
18 / 69
Single+Local git. Logs.
git log
Shows details of the commits.
git
log
working
directory
staging
area
master
19 / 69
Single+Local git. Logs.
gitk
GUI to browse the git repository.
20 / 69
Single+Local git. “How to clean this mess??” OPT.
git checkout <filename>
Get rid of what changed in <filename> (between working dir
and staging area).
working
directory
staging
area
master
git checkout
<file> <dir>
21 / 69
Single+Local git. Time travelling. OPTIONAL
Back to the past when you did commit dbb49293790b84...
git checkout dbb4929
...and now, back to the present!
git checkout master
22 / 69
Single+Local git. “How to clean this mess??”. OPT.
First read carefully git status. If you panic:
git reset --hard HEAD
Restore all files as in the last commit.
working
directory
staging
area
master
git reset --hard git reset --hard
Warning: reset can destroy history!
23 / 69
Single+Local git. (Re)move. OPTIONAL
Warning: whenever you want to remove, move or rename a
tracked file use git:
git rm <filename>
git mv <oldname> <newname>
Remember to commit these changes!
git commit -m "File (re)moved."
24 / 69
Single+Local git. Demo.
Demo: demo_git_single_local.txt
25 / 69
multi+remote/shared git.
Scenario 2: multiple developers + remote central repository.
26 / 69
multi+remote/shared git.
shared repository
developer developerdeveloper
27 / 69
multi+remote/shared git.
working
directory
staging
area
master
git add
git commit
git checkout
git merge
git push
git fetch
Local Remote
master
remote/
origin/
master
28 / 69
multi+remote/shared git.
git clone <URL>
Creates two local copies of the whole remote repository.
Remote
master
Available transport protocols:
ssh://, git://, http://, https://, file://
Ex.: git clone https://github.com/ASPP/pelita.git
git remote -v
shows name and URL of the remote repository.
29 / 69
multi+remote/shared git.
git clone <URL>
Creates two local copies of the whole remote repository.
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
git clone
Available transport protocols:
ssh://, git://, http://, https://, file://
Ex.: git clone https://github.com/ASPP/pelita.git
git remote -v
shows name and URL of the remote repository.
30 / 69
multi+remote/shared git. Fetch.
git fetch
Downloads updates from remote master to local remote
master.
The local master, staging area and working directory do
not change.
working
directory
staging
area
master
git fetch
Local Remote
master
remote/
origin/
master
Q: Why origin?
A: Just a label for Remote. Choose the one you like.
31 / 69
multi+remote/shared git. Merge.
git merge
Joins development histories together.
Warning: can generate conflicts!
Note: it merges only when all changes are committed.
working
directory
staging
area
master
Local Remote
master
git merge
remote/
origin/
master
git fetch + git merge = git pull
32 / 69
multi+remote/shared git. Conflicts.
Conflict!
...
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let’s go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
...
33 / 69
multi+remote/shared git. Conflicts.
How to resolve conflicts.
1 See where conflicts are:
git diff
2 Edit conflicting lines.
3 Add changes to the staging area:
git add file1 [...]
4 Commit changes:
git commit -m "Conflicts solved."
34 / 69
multi+remote/shared git.
git push
Updates remote masters (both Local and Remote).
Requires fetch+merge first.
working
directory
staging
area
master
git push
Local Remote
master
remote/
origin/
master
35 / 69
multi+remote/shared git.
Demo: demo_git_multi_remote.txt.
Other related files:
create_remote_repo_sn.sh
collaborator1.sh
collaborator2.sh
collaborator2.sh
36 / 69
Branching.
basic branching
37 / 69
Branching.
git commit (C0)
git commit (C1)
git commit (C2)
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
38 / 69
Branching.
git branch iss53
git checkout iss53
git checkout master
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
39 / 69
Branching.
git branch iss53
git checkout iss53
git checkout master
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
40 / 69
Branching.
git branch iss53
git checkout iss53
git checkout master
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
41 / 69
Branching.
git checkout iss53
git commit (C3)
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
42 / 69
Branching.
git branch hotfix
git checkout hotfix
git commit (C4)
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
hotfix
43 / 69
Branching.
git branch hotfix
git checkout hotfix
git commit (C4)
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
hotfix
44 / 69
Branching.
git checkout master
git merge hotfix
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
hotfix
45 / 69
Branching.
git checkout iss53
git commit (C5)
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
46 / 69
Branching.
git checkout master
git merge iss53
working
directory
staging
area
master
Local Remote
master
remote/
origin/
master
iss53
hotfix
47 / 69
Contributing through GitHub
Scenario 3: contributing to a software project hosted on GitHub.
48 / 69
Contributing through GitHub
Q: Have you ever heard of GitHub?
What is GitHub?
Wikipedia: “GitHub is a web-based hosting service for
software development projects that use git”.
5 millions repositories (Jan 2013).
Commercial...
...but friendly to Free / Open Source software projects.
49 / 69
Contributing through GitHub
Assumptions
You use a software and feel ready to contribute to it.
The software project is hosted on http://github.com
Intuitive Idea
You do not push your changes to the main repository.
Instead you create a public copy (fork) of the main
repository...
...and then push your changes to that.
Then you ask the owners of the main repository if they like
your changes and want to merge them (pull request).
50 / 69
Contributing through GitHub. Not for everyone ;-)
https://github.com/torvalds/linux/pull/17
51 / 69
Contributing through GitHub: Recipe I
1 Register on http://github.com
2 Visit the GitHub page of the software project and Fork it:
3 Clone your copy of the project on your computer.
git clone git@github.com:<login>/<project>.git
4 Create a branch to host your improvements.
git branch <new-feature>
git checkout <new-feature>
52 / 69
Contributing through GitHub: Recipe II
5 Add your improvements.
git add <new-file>
git commit -m ...
6 Push your improvements.
git push origin <new-feature>
7 Send a pull request.
53 / 69
Contributing through GitHub
Detailed Explanation
54 / 69
Contributing through GitHub: Detailed Explanation
Remote / Upstream
master
There is a software project hosted on remote GitHub repository
(upstream). You want to improve it.
55 / 69
Contributing through GitHub: Detailed Explanation
Remote / Origin
master
Remote / Upstream
master
So you fork it by creating a (remote) copy of it:
git clone --bare <UPSTREAM_URL>
56 / 69
Contributing through GitHub: Detailed Explanation
working
directory
staging
area
Local
Remote / Origin
master
remote/
origin/
master
Remote / Upstream
master
master
Now you clone your copy on your local computer:
git clone <ORIGIN_URL>
57 / 69
Contributing through GitHub: Detailed Explanation
working
directory
staging
area
Local
Remote / Origin
master
remote/
origin/
master
Remote / Upstream
master
remote/
upstream/
master
master
git remote add upstream <UPSTREAM_URL>
git fetch upstream
58 / 69
Contributing through GitHub: Detailed Explanation
working
directory
staging
area
Local
Remote / Origin
master
remote/
origin/
master
new-feature
Remote / Upstream
master
remote/
upstream/
master
master
git branch new-feature upstream/master
git checkout new-feature
59 / 69
Contributing through GitHub: Detailed Explanation
working
directory
staging
area
Local
Remote / Origin
master
remote/
origin/
master
new-feature
Remote / Upstream
master
remote/
upstream/
master
master
git add ...
git commit ...
60 / 69
Contributing through GitHub: Detailed Explanation
working
directory
staging
area
Local
Remote / Origin
master
remote/
origin/
new-feature
master
new-feature
remote/
origin/
Remote / Upstream
master
new-feature
remote/
upstream/
master
master
publish your new feature:
git push origin new-feature
61 / 69
Contributing through GitHub: Detailed Explanation
working
directory
staging
area
Local
Remote / Origin
master
remote/
origin/
new-feature
master
new-feature
remote/
origin/
Remote / Upstream
master
new-feature
remote/
upstream/
master
master
Notify the owners of the main repository about new-feature
they: git fetch + (eventually) git merge
62 / 69
Setting up a remote+shared repository. OPTIONAL
GOAL: I want to share my local repository so others can push.
“Why can’t I just extend permissions in my local repo?”
Yes you can...
...but your colleagues will not push (read-only).
To have it read-write: set up a remote shared repository.
shared repository
developer developerdeveloper
63 / 69
Setting up a remote+shared repository. OPTIONAL
You have a local repository and want to share it (ssh) from a
remote server on which your colleagues already have access.
On remote server create bare+shared repository:
mkdir newproject
set up proper group permissions: chmod g+rws
newproject
cd newproject
git --bare init --shared=group
On local machine push your repository to remote:
git remote add origin
ssh://remote.com/path/newproject
git push -u origin master
64 / 69
Setting up a remote+shared repository. OPTIONAL
Demo: demo_git_setup_remote.txt.
65 / 69
Credits
Rike-Benjamin Schuppner
Zbigniew J˛edrzejewski-Szmek
Tiziano Zito
Bastian Venthur
http://progit.com
apcmag.com
lwn.net
http://www.markus-gattol.name/ws/scm.html
http://matthew-brett.github.io/pydagogue/
gitwash/git_development.html
66 / 69
I want to know more about git!
Understanding how git works:
git foundations, by Matthew Brett:
http://matthew-brett.github.com/pydagogue/
foundation.html
The git parable, by Tom Preston-Werner:
http://tom.preston-werner.com/2009/05/19/
the-git-parable.html
Excellent guides:
“Pro Git” book: http://git-scm.com/book (FREE)
git magic: http://www-cs-students.stanford.
edu/~blynn/gitmagic/
Contributing to a project hosted on GitHub:
“Gitwash”, by Matthew Brett:
http://matthew-brett.github.io/pydagogue/
gitwash/git_development.html
67 / 69
Cool Stuff
Gource:
http://code.google.com/p/gource/
68 / 69
License
Copyright Emanuele Olivetti, 2014
This presentation is distributed under the license
Creative Commons Attribution 3.0
https://creativecommons.org/licenses/by/3.0/
The diagrams of the branching example are taken from Pro Git,
(copyright S.Chacon, 2009) and are distributed under the license
Creative Commons 3.0 Attribution-Non Commercial-Share Alike.
69 / 69

Contenu connexe

Tendances

Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with GitLuigi De Russis
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeMd Swawibe Ul Alam
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHubNicolás Tourné
 
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 overviewRueful Robin
 
Git slides
Git slidesGit slides
Git slidesNanyak S
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to gitJoel Krebs
 

Tendances (20)

Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git basic
Git basicGit basic
Git basic
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with Git
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git and github
Git and githubGit and github
Git and github
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
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 slides
Git slidesGit slides
Git slides
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
 

En vedette

GIT presentation
GIT presentationGIT presentation
GIT presentationNaim Latifi
 
Distributed Version Control Systems: A Guide For The Perplexed
Distributed Version Control Systems: A Guide For The PerplexedDistributed Version Control Systems: A Guide For The Perplexed
Distributed Version Control Systems: A Guide For The PerplexedAlan Stevens
 
Дмитрий Йовдий
Дмитрий ЙовдийДмитрий Йовдий
Дмитрий ЙовдийOleg Samoilow
 
Stock market in turkey
Stock market in turkeyStock market in turkey
Stock market in turkeySalman Agha
 
Conatsai
ConatsaiConatsai
Conatsaihmnava
 
Pdf báo tháng 9
Pdf báo tháng 9Pdf báo tháng 9
Pdf báo tháng 9bluelanu
 
US Manufacturing Renaissance
US Manufacturing RenaissanceUS Manufacturing Renaissance
US Manufacturing Renaissancesneapa
 
Land Use Law
Land Use LawLand Use Law
Land Use Lawsneapa
 
Cd – album covers
Cd – album coversCd – album covers
Cd – album coverstpark132
 
Presentación power point electricity
Presentación power point electricityPresentación power point electricity
Presentación power point electricityibencam
 
K4 identifikasi stok morfologi
K4 identifikasi stok morfologiK4 identifikasi stok morfologi
K4 identifikasi stok morfologiAli Putro
 
Павленко Юлия
Павленко ЮлияПавленко Юлия
Павленко ЮлияOleg Samoilow
 
Imc2+f2012 (1)
Imc2+f2012 (1)Imc2+f2012 (1)
Imc2+f2012 (1)Emma Daly
 
기아자동차 Uvo 프로젝트
기아자동차 Uvo 프로젝트기아자동차 Uvo 프로젝트
기아자동차 Uvo 프로젝트mchan21
 
Semantyka w tworzeniu stron www prezentacja
Semantyka w tworzeniu stron www   prezentacjaSemantyka w tworzeniu stron www   prezentacja
Semantyka w tworzeniu stron www prezentacjaPiotr Nalepa
 
Communication skills-5083
Communication skills-5083Communication skills-5083
Communication skills-5083Fanta_tarta
 

En vedette (18)

GIT presentation
GIT presentationGIT presentation
GIT presentation
 
Distributed Version Control Systems: A Guide For The Perplexed
Distributed Version Control Systems: A Guide For The PerplexedDistributed Version Control Systems: A Guide For The Perplexed
Distributed Version Control Systems: A Guide For The Perplexed
 
Дмитрий Йовдий
Дмитрий ЙовдийДмитрий Йовдий
Дмитрий Йовдий
 
Stock market in turkey
Stock market in turkeyStock market in turkey
Stock market in turkey
 
Conatsai
ConatsaiConatsai
Conatsai
 
Pdf báo tháng 9
Pdf báo tháng 9Pdf báo tháng 9
Pdf báo tháng 9
 
US Manufacturing Renaissance
US Manufacturing RenaissanceUS Manufacturing Renaissance
US Manufacturing Renaissance
 
Land Use Law
Land Use LawLand Use Law
Land Use Law
 
Cd – album covers
Cd – album coversCd – album covers
Cd – album covers
 
Presentación power point electricity
Presentación power point electricityPresentación power point electricity
Presentación power point electricity
 
Passive voice sil
Passive voice sil Passive voice sil
Passive voice sil
 
Inferences
InferencesInferences
Inferences
 
K4 identifikasi stok morfologi
K4 identifikasi stok morfologiK4 identifikasi stok morfologi
K4 identifikasi stok morfologi
 
Павленко Юлия
Павленко ЮлияПавленко Юлия
Павленко Юлия
 
Imc2+f2012 (1)
Imc2+f2012 (1)Imc2+f2012 (1)
Imc2+f2012 (1)
 
기아자동차 Uvo 프로젝트
기아자동차 Uvo 프로젝트기아자동차 Uvo 프로젝트
기아자동차 Uvo 프로젝트
 
Semantyka w tworzeniu stron www prezentacja
Semantyka w tworzeniu stron www   prezentacjaSemantyka w tworzeniu stron www   prezentacja
Semantyka w tworzeniu stron www prezentacja
 
Communication skills-5083
Communication skills-5083Communication skills-5083
Communication skills-5083
 

Similaire à A Practical Introduction to git

Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
HackMTY - GitHub Workshop
HackMTY - GitHub WorkshopHackMTY - GitHub Workshop
HackMTY - GitHub WorkshopLuis Lamadrid
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developersWim Godden
 
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 the Docs: Learning Git in a safe space
Git the Docs: Learning Git in a safe spaceGit the Docs: Learning Git in a safe space
Git the Docs: Learning Git in a safe spaceBecky Todd
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 WorkshopJoy Seng
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - WorkflowTahsin Abrar
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshellalignan
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenchesNuno Caneco
 

Similaire à A Practical Introduction to git (20)

Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Git introduction
Git introductionGit introduction
Git introduction
 
HackMTY - GitHub Workshop
HackMTY - GitHub WorkshopHackMTY - GitHub Workshop
HackMTY - GitHub Workshop
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developers
 
Git workshop
Git workshopGit workshop
Git workshop
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GIT
 
Git
GitGit
Git
 
Git training
Git trainingGit training
Git training
 
Git github
Git githubGit github
Git 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?
 
Git the Docs: Learning Git in a safe space
Git the Docs: Learning Git in a safe spaceGit the Docs: Learning Git in a safe space
Git the Docs: Learning Git in a safe space
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)Git Init (Introduction to Git)
Git Init (Introduction to Git)
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 Workshop
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
 
1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenches
 

Dernier

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 

Dernier (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 

A Practical Introduction to git

  • 1. A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind and Brain Sciences (CIMeC), University of Trento, Italy http://nilab.fbk.eu olivetti@fbk.eu 1 / 69
  • 2. Outline Version Control: git. Scenario 1: single developer, local repository. Demo single+local Scenario 2: Team of developers, central remote repository. Minimalistic. Demo multi+remote Branching. Scenario 3: Contributing to a Software Project hosted on GitHub. Extras: how to set up centralised repository, and more. 2 / 69
  • 3. Version Control: Naming & Meaning Wikipedia “Revision control, also known as version control, source control or software configuration management (SCM), is the management of changes to documents, programs, and other information stored as computer files.” Popular Acronyms: VC SCM Misnomer: Versioning Q: have you ever used VC? (raise your hand = YES) 3 / 69
  • 4. Version Control: Local, Centralized, Distributed From Pro Git, S.Chacon 2009, CC 3.0 license. 4 / 69
  • 5. Survey: git Q1: Have you heard about git? Q2: Do you use git? Q3: Why the “git” name? (from git FAQ) 1 Random three-letter combination that is pronounceable. 2 Acronym (global information tracker). 3 Irony. 5 / 69
  • 6. git? Why “git”? Linus Torvalds: “I name all my projects after myself. First Linux, now git.” http://www.merriam-webster. com/dictionary/git 6 / 69
  • 7. git git usage: git [OPTIONS] COMMAND [ARGS] The most commonly used git commands are: add Add file contents to the index commit Record changes to the repository diff Show changes between commits, commit a ... git help <command> git status 7 / 69
  • 8. git Introduce yourself to git: git config --global user.name "Emanuele Olivetti" git config --global user.email "olivetti@fbk.eu" 8 / 69
  • 9. git. Single developer + local repository. Scenario 1: single developer + local repository. 9 / 69
  • 10. Single+Local git. Motivations. Q: do you use VC for local repo? Why VC for single developer + local repository? First step towards a shared project. Backup. To keep the memory of your work. 10 / 69
  • 11. Single+Local git. Init. git init Creates an empty git repository. Creates the git directory: .git/ working directory staging area master Note: it is safe. It does not change your pre-existing files. 11 / 69
  • 12. Single+Local git. The tracking process. git add <filename> working directory staging area master git add git commit git commit -m "Let us begin." Wikipedia “A staging area is a location where organisms, people, vehicles, equipment or material are assembled before use”. 12 / 69
  • 13. Single+Local git. Add. git add file1 [file2 ...] Adds new files for next commit. Adds content from working dir to the staging area (index) for next commit. DOES NOT add info on file permissions other than exec/noexec (755 / 644). DOES not add directories per se. working directory staging area master git add 13 / 69
  • 14. Single+Local git. Commit. git commit [-m "Commit message."] Records changes from the staging area to master. working directory staging area master git commit 14 / 69
  • 15. Single+Local git. Commit. git commit file1 file2 Records all changes of file1, file2 from working dir and staging area to master. working directory staging area master git commit <filename> git commit -a Records all changes in working dir and staging area. Be Careful! 15 / 69
  • 16. Single+Local git. Commit names. OPTIONAL Every commit is a git-object. The history of a project is a graph of objects referenced by a 40-digit git-name: SHA1(object). SHA1(object) = 160-bit Secure Hash Algorithm. Examples: $ git commit README -m "Added README." [master dbb4929] Added README. 1 files changed, 1 insertions(+), ... or $ git log commit dbb49293790b84f0bdcd74fd9fa5cab0... Author: Emanuele Olivetti <olivetti@fbk.eu> Date: Wed Sep 15 00:08:46 2010 +0200 ... 16 / 69
  • 17. Single+Local git. Diff. git diff Shows what changes between working directory and staging area (index). working directory staging area master git diff 17 / 69
  • 18. Single+Local git. Diff. OPTIONAL Q: “git add” then “git diff”. What output? git diff --cached shows differences between index and last commit (HEAD). working directory staging area master git diff --cached 18 / 69
  • 19. Single+Local git. Logs. git log Shows details of the commits. git log working directory staging area master 19 / 69
  • 20. Single+Local git. Logs. gitk GUI to browse the git repository. 20 / 69
  • 21. Single+Local git. “How to clean this mess??” OPT. git checkout <filename> Get rid of what changed in <filename> (between working dir and staging area). working directory staging area master git checkout <file> <dir> 21 / 69
  • 22. Single+Local git. Time travelling. OPTIONAL Back to the past when you did commit dbb49293790b84... git checkout dbb4929 ...and now, back to the present! git checkout master 22 / 69
  • 23. Single+Local git. “How to clean this mess??”. OPT. First read carefully git status. If you panic: git reset --hard HEAD Restore all files as in the last commit. working directory staging area master git reset --hard git reset --hard Warning: reset can destroy history! 23 / 69
  • 24. Single+Local git. (Re)move. OPTIONAL Warning: whenever you want to remove, move or rename a tracked file use git: git rm <filename> git mv <oldname> <newname> Remember to commit these changes! git commit -m "File (re)moved." 24 / 69
  • 25. Single+Local git. Demo. Demo: demo_git_single_local.txt 25 / 69
  • 26. multi+remote/shared git. Scenario 2: multiple developers + remote central repository. 26 / 69
  • 28. multi+remote/shared git. working directory staging area master git add git commit git checkout git merge git push git fetch Local Remote master remote/ origin/ master 28 / 69
  • 29. multi+remote/shared git. git clone <URL> Creates two local copies of the whole remote repository. Remote master Available transport protocols: ssh://, git://, http://, https://, file:// Ex.: git clone https://github.com/ASPP/pelita.git git remote -v shows name and URL of the remote repository. 29 / 69
  • 30. multi+remote/shared git. git clone <URL> Creates two local copies of the whole remote repository. working directory staging area master Local Remote master remote/ origin/ master git clone Available transport protocols: ssh://, git://, http://, https://, file:// Ex.: git clone https://github.com/ASPP/pelita.git git remote -v shows name and URL of the remote repository. 30 / 69
  • 31. multi+remote/shared git. Fetch. git fetch Downloads updates from remote master to local remote master. The local master, staging area and working directory do not change. working directory staging area master git fetch Local Remote master remote/ origin/ master Q: Why origin? A: Just a label for Remote. Choose the one you like. 31 / 69
  • 32. multi+remote/shared git. Merge. git merge Joins development histories together. Warning: can generate conflicts! Note: it merges only when all changes are committed. working directory staging area master Local Remote master git merge remote/ origin/ master git fetch + git merge = git pull 32 / 69
  • 33. multi+remote/shared git. Conflicts. Conflict! ... <<<<<<< yours:sample.txt Conflict resolution is hard; let’s go shopping. ======= Git makes conflict resolution easy. >>>>>>> theirs:sample.txt ... 33 / 69
  • 34. multi+remote/shared git. Conflicts. How to resolve conflicts. 1 See where conflicts are: git diff 2 Edit conflicting lines. 3 Add changes to the staging area: git add file1 [...] 4 Commit changes: git commit -m "Conflicts solved." 34 / 69
  • 35. multi+remote/shared git. git push Updates remote masters (both Local and Remote). Requires fetch+merge first. working directory staging area master git push Local Remote master remote/ origin/ master 35 / 69
  • 36. multi+remote/shared git. Demo: demo_git_multi_remote.txt. Other related files: create_remote_repo_sn.sh collaborator1.sh collaborator2.sh collaborator2.sh 36 / 69
  • 38. Branching. git commit (C0) git commit (C1) git commit (C2) working directory staging area master Local Remote master remote/ origin/ master 38 / 69
  • 39. Branching. git branch iss53 git checkout iss53 git checkout master working directory staging area master Local Remote master remote/ origin/ master iss53 39 / 69
  • 40. Branching. git branch iss53 git checkout iss53 git checkout master working directory staging area master Local Remote master remote/ origin/ master iss53 40 / 69
  • 41. Branching. git branch iss53 git checkout iss53 git checkout master working directory staging area master Local Remote master remote/ origin/ master iss53 41 / 69
  • 42. Branching. git checkout iss53 git commit (C3) working directory staging area master Local Remote master remote/ origin/ master iss53 42 / 69
  • 43. Branching. git branch hotfix git checkout hotfix git commit (C4) working directory staging area master Local Remote master remote/ origin/ master iss53 hotfix 43 / 69
  • 44. Branching. git branch hotfix git checkout hotfix git commit (C4) working directory staging area master Local Remote master remote/ origin/ master iss53 hotfix 44 / 69
  • 45. Branching. git checkout master git merge hotfix working directory staging area master Local Remote master remote/ origin/ master iss53 hotfix 45 / 69
  • 46. Branching. git checkout iss53 git commit (C5) working directory staging area master Local Remote master remote/ origin/ master iss53 46 / 69
  • 47. Branching. git checkout master git merge iss53 working directory staging area master Local Remote master remote/ origin/ master iss53 hotfix 47 / 69
  • 48. Contributing through GitHub Scenario 3: contributing to a software project hosted on GitHub. 48 / 69
  • 49. Contributing through GitHub Q: Have you ever heard of GitHub? What is GitHub? Wikipedia: “GitHub is a web-based hosting service for software development projects that use git”. 5 millions repositories (Jan 2013). Commercial... ...but friendly to Free / Open Source software projects. 49 / 69
  • 50. Contributing through GitHub Assumptions You use a software and feel ready to contribute to it. The software project is hosted on http://github.com Intuitive Idea You do not push your changes to the main repository. Instead you create a public copy (fork) of the main repository... ...and then push your changes to that. Then you ask the owners of the main repository if they like your changes and want to merge them (pull request). 50 / 69
  • 51. Contributing through GitHub. Not for everyone ;-) https://github.com/torvalds/linux/pull/17 51 / 69
  • 52. Contributing through GitHub: Recipe I 1 Register on http://github.com 2 Visit the GitHub page of the software project and Fork it: 3 Clone your copy of the project on your computer. git clone git@github.com:<login>/<project>.git 4 Create a branch to host your improvements. git branch <new-feature> git checkout <new-feature> 52 / 69
  • 53. Contributing through GitHub: Recipe II 5 Add your improvements. git add <new-file> git commit -m ... 6 Push your improvements. git push origin <new-feature> 7 Send a pull request. 53 / 69
  • 55. Contributing through GitHub: Detailed Explanation Remote / Upstream master There is a software project hosted on remote GitHub repository (upstream). You want to improve it. 55 / 69
  • 56. Contributing through GitHub: Detailed Explanation Remote / Origin master Remote / Upstream master So you fork it by creating a (remote) copy of it: git clone --bare <UPSTREAM_URL> 56 / 69
  • 57. Contributing through GitHub: Detailed Explanation working directory staging area Local Remote / Origin master remote/ origin/ master Remote / Upstream master master Now you clone your copy on your local computer: git clone <ORIGIN_URL> 57 / 69
  • 58. Contributing through GitHub: Detailed Explanation working directory staging area Local Remote / Origin master remote/ origin/ master Remote / Upstream master remote/ upstream/ master master git remote add upstream <UPSTREAM_URL> git fetch upstream 58 / 69
  • 59. Contributing through GitHub: Detailed Explanation working directory staging area Local Remote / Origin master remote/ origin/ master new-feature Remote / Upstream master remote/ upstream/ master master git branch new-feature upstream/master git checkout new-feature 59 / 69
  • 60. Contributing through GitHub: Detailed Explanation working directory staging area Local Remote / Origin master remote/ origin/ master new-feature Remote / Upstream master remote/ upstream/ master master git add ... git commit ... 60 / 69
  • 61. Contributing through GitHub: Detailed Explanation working directory staging area Local Remote / Origin master remote/ origin/ new-feature master new-feature remote/ origin/ Remote / Upstream master new-feature remote/ upstream/ master master publish your new feature: git push origin new-feature 61 / 69
  • 62. Contributing through GitHub: Detailed Explanation working directory staging area Local Remote / Origin master remote/ origin/ new-feature master new-feature remote/ origin/ Remote / Upstream master new-feature remote/ upstream/ master master Notify the owners of the main repository about new-feature they: git fetch + (eventually) git merge 62 / 69
  • 63. Setting up a remote+shared repository. OPTIONAL GOAL: I want to share my local repository so others can push. “Why can’t I just extend permissions in my local repo?” Yes you can... ...but your colleagues will not push (read-only). To have it read-write: set up a remote shared repository. shared repository developer developerdeveloper 63 / 69
  • 64. Setting up a remote+shared repository. OPTIONAL You have a local repository and want to share it (ssh) from a remote server on which your colleagues already have access. On remote server create bare+shared repository: mkdir newproject set up proper group permissions: chmod g+rws newproject cd newproject git --bare init --shared=group On local machine push your repository to remote: git remote add origin ssh://remote.com/path/newproject git push -u origin master 64 / 69
  • 65. Setting up a remote+shared repository. OPTIONAL Demo: demo_git_setup_remote.txt. 65 / 69
  • 66. Credits Rike-Benjamin Schuppner Zbigniew J˛edrzejewski-Szmek Tiziano Zito Bastian Venthur http://progit.com apcmag.com lwn.net http://www.markus-gattol.name/ws/scm.html http://matthew-brett.github.io/pydagogue/ gitwash/git_development.html 66 / 69
  • 67. I want to know more about git! Understanding how git works: git foundations, by Matthew Brett: http://matthew-brett.github.com/pydagogue/ foundation.html The git parable, by Tom Preston-Werner: http://tom.preston-werner.com/2009/05/19/ the-git-parable.html Excellent guides: “Pro Git” book: http://git-scm.com/book (FREE) git magic: http://www-cs-students.stanford. edu/~blynn/gitmagic/ Contributing to a project hosted on GitHub: “Gitwash”, by Matthew Brett: http://matthew-brett.github.io/pydagogue/ gitwash/git_development.html 67 / 69
  • 69. License Copyright Emanuele Olivetti, 2014 This presentation is distributed under the license Creative Commons Attribution 3.0 https://creativecommons.org/licenses/by/3.0/ The diagrams of the branching example are taken from Pro Git, (copyright S.Chacon, 2009) and are distributed under the license Creative Commons 3.0 Attribution-Non Commercial-Share Alike. 69 / 69