a version-control system
Paweł Mleczko
Faculty of Mathematics and Computer Science
Adam Mickiewicz University in Poznań

Topics

- What is GIT?
- How does it work?
- Basic commends
- GUI vs. command line
- repositories
What is GIT?
GIT is a version control system for tracking changes and exchange files among users.

Basic usage

Three friends works on the same document in teh same time.
How can they do this?
Who does use GIT?
- programmers (Androida, GIMP-a, jQuery, Linux-a, Symfony)
- authors of books and articles
- authors of educational stuff

What kind of files can be tracked?
The power of text files!

Basic advantages
- coordinate works of many authors
- allows to coordinate and manage project
- structureizes work
- ensures safety (backups)
The author of GIT


Linus Torvalds (born 1969), Finnish programmer, the author of Linux kernel.
How does it work?

Basic terms
- repository (repo)
- commit
- pull / push
- diff
- branch
- merge

States of files

Branches

Basic commends

A test repository at GitHub
Configuration

$ git config --global user.name "First name Last name"
$ git config --global core.editor nano
$ git config --global user.email jannowak@example.com
Creating repository (locally)

$ git init
Cloning a repository
git clone 'repozytorium'
for example
$ git clone git@github.com:pml-pml/nidn2017.git
Cloning into 'nidn2017'...
The authenticity of host 'github.com (192.30.253.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

States of files
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
lorem.txt
nothing added to commit but untracked files present (use "git add" to track)

Adding files

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: lorem.txt
$ git add lorem.txt
Puting changes into local repo

$ git commit -m "dodanie pliku z fragmentem lorem ipsum"
[master ff54873] dodanie pliku z fragmentem lorem ipsum
1 file changed, 1 insertion(+)
create mode 100644 lorem.txt
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
Pushing changes

$ git push
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 566 bytes | 566.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:pml-pml/nidn2017.git
f05826b..ff54873 master -> master
$ git push
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 566 bytes | 566.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:pml-pml/nidn2017.git
f05826b..ff54873 master -> master
Fetching changes

$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:pml-pml/nidn2017
ff54873..6faf81e master -> origin/master
Updating ff54873..6faf81e
Fast-forward
lorem.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
$ git pull
Merging changes

$ git push
Username for 'https://github.com': pml-pml
Password for 'https://pml-pml@github.com':
To https://github.com/pml-pml/nidn2017.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/pml-pml/nidn2017.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Merging changes

$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/pml-pml/nidn2017
6faf81e..a54bb68 master -> origin/master
Auto-merging lorem.txt
CONFLICT (content): Merge conflict in lorem.txt
Automatic merge failed; fix conflicts and then commit the result.
Merging changes


Merging changes


Merging changes


Diff

$ git log
commit 1c173d64cf80e2a8cfb7b22ff76f891f23c329cd (HEAD -> master, origin/master, origin/HEAD)
Merge: 03195c9 a54bb68
Author: Paweł Mleczko <pml@amu.edu.pl>
Date: Tue Oct 24 12:59:01 2017 +0200
rozwiązanie konfliktu wyróżnienie/podkreślenie
commit 03195c925dcd30085d7cd52a663499eec99e5f2b
Author: Paweł Mleczko <pml@amu.edu.pl>
Date: Tue Oct 24 12:51:01 2017 +0200
wyróżnienie drugiego słowa w pierwszym akapicie
commit a54bb68b97338505cd6ac7d8f258bf275b37086e
Author: Paweł Mleczko <pml@amu.edu.pl>
Date: Tue Oct 24 12:49:16 2017 +0200
podkreślenie drugiego słowa w pierwszym akapicie
commit 6faf81e39188194c53200ba1352a88effb8bb439
Author: Paweł Mleczko <pml@amu.edu.pl>
Date: Mon Oct 23 17:24:30 2017 +0200
dopisanie drugiego akapitu
Revise the last change

$ git show
commit 1c173d64cf80e2a8cfb7b22ff76f891f23c329cd (HEAD -> master, origin/master, origin/HEAD)
Merge: 03195c9 a54bb68
Author: Paweł Mleczko <pml@amu.edu.pl>
Date: Tue Oct 24 12:59:01 2017 +0200
rozwiązanie konfliktu wyróżnienie/podkreślenie
GUI vs. command line

command line
$ git clone git@github.com:pml-pml/nidn2017.git
Cloning into 'nidn2017'...
The authenticity of host 'github.com (192.30.253.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
GUI

Best practise

- name commits in readable format
- separate branch for different functionalities, chapter etc
- pushing to a remote repository only working parts of code
Online services
- GitHub https://github.com/
- Bitbucket https://bitbucket.org/
- GitLab https://gitlab.com/
- GitWMI http://git.wmi.amu.edu.pl/

Where to store repositories?


Where to store repositories?

pros
- free private repos for small teams (up to five users)
cons
- stability problems

Where to store repositories?


Where to store repositories?


Https or ssh?

- ssh, easy command line pushing with public key
- https - otherwise
What to do if it doesn't work?


More information?
Manual

What else?
For example:
- Dropbox https://www.dropbox.com/
- Google Drive https://www.google.com/drive/
- many other serices (MEGAsync)
In most cases no tracking changes possibilities.

GIT
By Pawel Mleczko
GIT
An introduction to GIT.
- 707