a practical introduction to git...a practical introduction to git emanuele olivetti neuroinformatics...
TRANSCRIPT
![Page 1: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/1.jpg)
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, Italyhttp://[email protected]
1 / 69
![Page 2: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/2.jpg)
Outline
Version Control: git.Scenario 1: single developer, local repository.
Demo single+localScenario 2: Team of developers, central remoterepository. Minimalistic.
Demo multi+remote
Branching.Scenario 3: Contributing to a Software Project hosted onGitHub.Extras: how to set up centralised repository, and more.
2 / 69
![Page 3: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/3.jpg)
Version Control: Naming & Meaning
Wikipedia
“Revision control, also known as version control, source controlor software configuration management (SCM), is themanagement of changes to documents, programs, and otherinformation stored as computer files.”
Popular Acronyms:VCSCM
Misnomer:Versioning
Q: have you ever used VC? (raise your hand = YES)
3 / 69
![Page 4: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/4.jpg)
Version Control: Local, Centralized, Distributed
From Pro Git, S.Chacon 2009, CC 3.0 license.4 / 69
![Page 5: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/5.jpg)
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
![Page 6: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/6.jpg)
git? Why “git”?
Linus Torvalds: “I name allmy projects after myself.First Linux, now git.”
http://www.merriam-webster.com/dictionary/git
6 / 69
![Page 7: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/7.jpg)
git
git
usage: git [OPTIONS] COMMAND [ARGS]
The most commonly used git commands are:add Add file contents to the indexcommit Record changes to the repositorydiff Show changes between commits, commit and working tree, etc...
git help <command>
git status
7 / 69
![Page 8: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/8.jpg)
git
Introduce yourself to git:
git config --global user.name "Emanuele Olivetti"
git config --global user.email "[email protected]"
8 / 69
![Page 9: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/9.jpg)
git. Single developer + local repository.
Scenario 1: single developer + local repository.
9 / 69
![Page 10: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/10.jpg)
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
![Page 11: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/11.jpg)
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
![Page 12: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/12.jpg)
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
![Page 13: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/13.jpg)
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 thanexec/noexec (755 / 644).DOES not add directories per se.
working directory
staging area master
git add
13 / 69
![Page 14: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/14.jpg)
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
![Page 15: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/15.jpg)
Single+Local git. Commit.
git commit file1 file2
Records all changes of file1, file2 from working dir andstaging area to master.
working directory
staging area master
git commit <filename>
git commit -a
Records all changes in working dir and staging area. BeCareful!
15 / 69
![Page 16: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/16.jpg)
Single+Local git. Commit names. OPTIONAL
Every commit is a git-object.The history of a project is a graph of objects referenced bya 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
![Page 17: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/17.jpg)
Single+Local git. Diff.
git diff
Shows what changes between working directory and stagingarea (index).
working directory
staging area master
git diff
17 / 69
![Page 18: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/18.jpg)
Single+Local git. Diff. OPTIONAL
Q: “git add” then “git diff”. What output?
git diff --cached shows differences between index andlast commit (HEAD).
working directory
staging area master
git diff --cached
18 / 69
![Page 19: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/19.jpg)
Single+Local git. Logs.
git log
Shows details of the commits.
git log
working directory
staging area master
19 / 69
![Page 20: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/20.jpg)
Single+Local git. Logs.
gitk
GUI to browse the git repository.
20 / 69
![Page 21: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/21.jpg)
Single+Local git. “How to clean this mess??” OPT.
git checkout <filename>
Get rid of what changed in <filename> (between working dirand staging area).
working directory
staging area master
git checkout <file> <dir>
21 / 69
![Page 22: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/22.jpg)
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
![Page 23: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/23.jpg)
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
![Page 24: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/24.jpg)
Single+Local git. (Re)move. OPTIONAL
Warning: whenever you want to remove, move or rename atracked file use git:
git rm <filename>
git mv <oldname> <newname>
Remember to commit these changes!
git commit -m "File (re)moved."
24 / 69
![Page 25: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/25.jpg)
Single+Local git. Demo.
Demo: demo_git_single_local.txt
25 / 69
![Page 26: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/26.jpg)
multi+remote/shared git.
Scenario 2: multiple developers + remote central repository.
26 / 69
![Page 27: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/27.jpg)
multi+remote/shared git.
shared repository
developer developerdeveloper
27 / 69
![Page 28: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/28.jpg)
multi+remote/shared git.
working directory
staging area master
git add
git commit
git checkout
git merge
git push
git fetch
Local Remote
masterremote/origin/master
28 / 69
![Page 29: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/29.jpg)
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
![Page 30: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/30.jpg)
multi+remote/shared git.
git clone <URL>
Creates two local copies of the whole remote repository.
workingdirectory
stagingarea master
Local Remote
masterremote/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
![Page 31: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/31.jpg)
multi+remote/shared git. Fetch.
git fetch
Downloads updates from remote master to local remotemaster.The local master, staging area and working directory donot change.
working directory
staging area master
git fetch
Local Remote
masterremote/origin/master
Q: Why origin?
A: Just a label for Remote. Choose the one you like.
31 / 69
![Page 32: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/32.jpg)
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
![Page 33: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/33.jpg)
multi+remote/shared git. Conflicts.
Conflict!
...<<<<<<< yours:sample.txtConflict resolution is hard;let’s go shopping.=======Git makes conflict resolution easy.>>>>>>> theirs:sample.txt...
33 / 69
![Page 34: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/34.jpg)
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
![Page 35: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/35.jpg)
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
masterremote/origin/master
35 / 69
![Page 36: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/36.jpg)
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
![Page 37: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/37.jpg)
Branching.
basic branching
37 / 69
![Page 38: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/38.jpg)
Branching.
git commit (C0)git commit (C1)git commit (C2)
working directory
staging area master
Local Remote
masterremote/origin/master
38 / 69
![Page 39: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/39.jpg)
Branching.
git branch iss53git checkout iss53git checkout master
workingdirectory
stagingarea master
Local Remote
masterremote/origin/master
iss53
39 / 69
![Page 40: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/40.jpg)
Branching.
git branch iss53git checkout iss53git checkout master
workingdirectory
stagingarea
master
Local Remote
masterremote/origin/master
iss53
40 / 69
![Page 41: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/41.jpg)
Branching.
git branch iss53git checkout iss53git checkout master
workingdirectory
stagingarea master
Local Remote
masterremote/origin/master
iss53
41 / 69
![Page 42: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/42.jpg)
Branching.
git checkout iss53git commit (C3)
workingdirectory
stagingarea
master
Local Remote
masterremote/origin/master
iss53
42 / 69
![Page 43: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/43.jpg)
Branching.
git branch hotfixgit checkout hotfix
git commit (C4)
workingdirectory
stagingarea master
Local Remote
masterremote/origin/master
iss53
hotfix
43 / 69
![Page 44: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/44.jpg)
Branching.
git branch hotfixgit checkout hotfix
git commit (C4)
workingdirectory
stagingarea
master
Local Remote
masterremote/origin/master
iss53
hotfix
44 / 69
![Page 45: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/45.jpg)
Branching.
git checkout mastergit merge hotfix
workingdirectory
stagingarea master
Local Remote
masterremote/origin/master
iss53
hotfix
45 / 69
![Page 46: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/46.jpg)
Branching.
git checkout iss53git commit (C5)
workingdirectory
stagingarea
master
Local Remote
masterremote/origin/master
iss53
46 / 69
![Page 47: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/47.jpg)
Branching.
git checkout mastergit merge iss53
workingdirectory
stagingarea master
Local Remote
masterremote/origin/master
iss53
hotfix
47 / 69
![Page 48: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/48.jpg)
Contributing through GitHub
Scenario 3: contributing to a software project hosted on GitHub.
48 / 69
![Page 49: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/49.jpg)
Contributing through GitHub
Q: Have you ever heard of GitHub?
What is GitHub?
Wikipedia: “GitHub is a web-based hosting service forsoftware development projects that use git”.5 millions repositories (Jan 2013).Commercial......but friendly to Free / Open Source software projects.
49 / 69
![Page 50: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/50.jpg)
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 mainrepository......and then push your changes to that.Then you ask the owners of the main repository if they likeyour changes and want to merge them (pull request).
50 / 69
![Page 51: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/51.jpg)
Contributing through GitHub. Not for everyone ;-)
https://github.com/torvalds/linux/pull/1751 / 69
![Page 52: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/52.jpg)
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
![Page 53: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/53.jpg)
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
![Page 54: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/54.jpg)
Contributing through GitHub
Detailed Explanation
54 / 69
![Page 55: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/55.jpg)
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
![Page 56: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/56.jpg)
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
![Page 57: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/57.jpg)
Contributing through GitHub: Detailed Explanation
workingdirectory
stagingarea
Local
Remote / Origin
masterremote/origin/master
Remote / Upstream
master
master
Now you clone your copy on your local computer:git clone <ORIGIN_URL>
57 / 69
![Page 58: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/58.jpg)
Contributing through GitHub: Detailed Explanation
workingdirectory
stagingarea
Local
Remote / Origin
masterremote/origin/master
Remote / Upstream
masterremote/
upstream/master
master
git remote add upstream <UPSTREAM_URL>git fetch upstream
58 / 69
![Page 59: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/59.jpg)
Contributing through GitHub: Detailed Explanation
workingdirectory
stagingarea
Local
Remote / Origin
masterremote/origin/master
new-feature
Remote / Upstream
masterremote/
upstream/master
master
git branch new-feature upstream/mastergit checkout new-feature
59 / 69
![Page 60: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/60.jpg)
Contributing through GitHub: Detailed Explanation
workingdirectory
stagingarea
Local
Remote / Origin
masterremote/origin/master
new-feature
Remote / Upstream
masterremote/
upstream/master
master
git add ...git commit ...
60 / 69
![Page 61: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/61.jpg)
Contributing through GitHub: Detailed Explanation
workingdirectory
stagingarea
Local
Remote / Origin
masterremote/origin/
new-feature
master
new-featureremote/origin/
Remote / Upstream
master
new-feature
remote/upstream/
master
master
publish your new feature:git push origin new-feature
61 / 69
![Page 62: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/62.jpg)
Contributing through GitHub: Detailed Explanation
workingdirectory
stagingarea
Local
Remote / Origin
masterremote/origin/
new-feature
master
new-featureremote/origin/
Remote / Upstream
master
new-feature
remote/upstream/
master
master
Notify the owners of the main repository about new-featurethey: git fetch + (eventually) git merge
62 / 69
![Page 63: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/63.jpg)
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
![Page 64: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/64.jpg)
Setting up a remote+shared repository. OPTIONAL
You have a local repository and want to share it (ssh) from aremote server on which your colleagues already have access.
On remote server create bare+shared repository:
mkdir newproject
set up proper group permissions: chmod g+rwsnewproject
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
Everybody clones the shared repository:
git clone ssh://remote.com/path/newproject
64 / 69
![Page 65: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/65.jpg)
Setting up a remote+shared repository. OPTIONAL
Demo: demo_git_setup_remote.txt.
65 / 69
![Page 66: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/66.jpg)
Credits
Rike-Benjamin SchuppnerZbigniew Jedrzejewski-SzmekTiziano ZitoBastian Venthurhttp://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
![Page 67: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/67.jpg)
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
![Page 69: A Practical Introduction to git...A Practical Introduction to git Emanuele Olivetti NeuroInformatics Laboratory (NILab) Bruno Kessler Foundation (FBK), Trento, Italy Center for Mind](https://reader030.vdocuments.us/reader030/viewer/2022040415/5f33d7caf8d03b4e71658abb/html5/thumbnails/69.jpg)
License
Copyright Emanuele Olivetti, 2014
This presentation is distributed under the licenseCreative 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 licenseCreative Commons 3.0 Attribution-Non Commercial-Share Alike.
69 / 69