SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
Behzad Altaf
 
Learning git
Learning gitLearning git
Learning git
Sid Anand
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
Anurag Upadhaya
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Git basics
Git basicsGit basics
Git basics
GHARSALLAH Mohamed
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
Introduction git
Introduction gitIntroduction git
Introduction git
Dian Sigit Prastowo
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
Naveen Pandey
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
KMS Technology
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
Nilay Binjola
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
 
Git real slides
Git real slidesGit real slides
Git real slides
Lucas Couto
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Rueful Robin
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
Sergiu-Ioan Ungur
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
E Carter
 
git and github
git and githubgit and github
git and github
Darren Oakley
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
Thomas Rausch
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
Venkat Malladi
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
Arnaud Seilles
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
Behzad Altaf
 
Learning git
Learning gitLearning git
Learning git
Sid Anand
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
Naveen Pandey
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
KMS Technology
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
Nilay Binjola
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Rueful Robin
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
E Carter
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
Thomas Rausch
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
Venkat Malladi
 

Viewers also liked (18)

GIT presentation
GIT presentationGIT presentation
GIT presentation
Naim 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 Perplexed
Alan Stevens
 
Дмитрий Йовдий
Дмитрий ЙовдийДмитрий Йовдий
Дмитрий Йовдий
Oleg Samoilow
 
Stock market in turkey
Stock market in turkeyStock market in turkey
Stock market in turkey
Salman Agha
 
Conatsai
ConatsaiConatsai
Conatsai
hmnava
 
Pdf báo tháng 9
Pdf báo tháng 9Pdf báo tháng 9
Pdf báo tháng 9
bluelanu
 
US Manufacturing Renaissance
US Manufacturing RenaissanceUS Manufacturing Renaissance
US Manufacturing Renaissance
sneapa
 
Land Use Law
Land Use LawLand Use Law
Land Use Law
sneapa
 
Cd – album covers
Cd – album coversCd – album covers
Cd – album covers
tpark132
 
Presentación power point electricity
Presentación power point electricityPresentación power point electricity
Presentación power point electricity
ibencam
 
Passive voice sil
Passive voice sil Passive voice sil
Passive voice sil
silvana_tandil
 
Inferences
InferencesInferences
Inferences
American Curriculum
 
K4 identifikasi stok morfologi
K4 identifikasi stok morfologiK4 identifikasi stok morfologi
K4 identifikasi stok morfologi
Ali 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 prezentacja
Piotr Nalepa
 
Communication skills-5083
Communication skills-5083Communication skills-5083
Communication skills-5083
Fanta_tarta
 
GIT presentation
GIT presentationGIT presentation
GIT presentation
Naim 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 Perplexed
Alan Stevens
 
Дмитрий Йовдий
Дмитрий ЙовдийДмитрий Йовдий
Дмитрий Йовдий
Oleg Samoilow
 
Stock market in turkey
Stock market in turkeyStock market in turkey
Stock market in turkey
Salman Agha
 
Conatsai
ConatsaiConatsai
Conatsai
hmnava
 
Pdf báo tháng 9
Pdf báo tháng 9Pdf báo tháng 9
Pdf báo tháng 9
bluelanu
 
US Manufacturing Renaissance
US Manufacturing RenaissanceUS Manufacturing Renaissance
US Manufacturing Renaissance
sneapa
 
Land Use Law
Land Use LawLand Use Law
Land Use Law
sneapa
 
Cd – album covers
Cd – album coversCd – album covers
Cd – album covers
tpark132
 
Presentación power point electricity
Presentación power point electricityPresentación power point electricity
Presentación power point electricity
ibencam
 
K4 identifikasi stok morfologi
K4 identifikasi stok morfologiK4 identifikasi stok morfologi
K4 identifikasi stok morfologi
Ali 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 prezentacja
Piotr Nalepa
 
Communication skills-5083
Communication skills-5083Communication skills-5083
Communication skills-5083
Fanta_tarta
 
Ad

Similar to 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
Max Claus Nunes
 
Git introduction
Git introductionGit introduction
Git introduction
satyendrajaladi
 
HackMTY - GitHub Workshop
HackMTY - GitHub WorkshopHackMTY - GitHub Workshop
HackMTY - GitHub Workshop
Luis Lamadrid
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developers
Wim Godden
 
Git workshop
Git workshopGit workshop
Git workshop
Mateusz Galazyn
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GIT
Piotr Benetkiewicz
 
Git
GitGit
Git
Hanokh Aloni
 
Git training
Git trainingGit training
Git training
eric7master
 
Git github
Git githubGit github
Git github
Anurag Deb
 
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 space
Becky Todd
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
Nguyen Van Hung
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)Git Init (Introduction to Git)
Git Init (Introduction to Git)
GDSC UofT Mississauga
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 Workshop
Joy Seng
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
Arashdeepkaur16
 
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
HuthaifaAlmaqrami1
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
Tahsin Abrar
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
alignan
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
Jesús Miguel Benito Calzada
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenches
Nuno Caneco
 
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 Workshop
Luis Lamadrid
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developers
Wim 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 space
Becky Todd
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 Workshop
Joy Seng
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
Tahsin Abrar
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
alignan
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenches
Nuno Caneco
 
Ad

Recently uploaded (20)

Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 

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 [email protected] 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 "[email protected]" 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 <[email protected]> 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 [email protected]:<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