Slide 1

Slide 1 text

Git Jussi Pohjolainen

Slide 2

Slide 2 text

Problem • Lost your work? • Made accidental update and want to go back? • Want to collabarate with other on the same files?

Slide 3

Slide 3 text

Solutions • Local Version Control • Copy files (manually) into another directory • Common, simple and may result for errors • Centralized Version Control (CVS) • Collaboration with others • All files are on a single server (central place) that clients access • If server is down, we have problems • Distributed Version Control Systems (DVCS) • Your local files are mirrored to the server • If server dies, you can continue with your work • Git is a DVCS

Slide 4

Slide 4 text

https://www.quora.com/How-is-Git-different-from-CVS

Slide 5

Slide 5 text

https://www.quora.com/How-is-Git-different-from-CVS

Slide 6

Slide 6 text

Getting Started

Slide 7

Slide 7 text

Installing • macOS • Install Xcode and Xcode Command Line Tools via App Store • Linux • sudo dnf install git-all • Windows • http://git-scm.com/download/win

Slide 8

Slide 8 text

Global Settings git config --list credential.helper=osxkeychain user.name=pohjus user.email=jussi.pohjolainen@tuni.fi core.editor=code filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true filter.lfs.clean=git-lfs clean -- %f credential.helper=cache --timeout=3600

Slide 9

Slide 9 text

Change Global Settings git config --global user.name "Max Power" git config --global user.email "max.power@gmail.com" Configure git, give name, e-mail of your choice

Slide 10

Slide 10 text

.gitconfig cat ~/.gitconfig [user] name = Jussi Pohjolainen email = jussi.pohjolainen@gmail.com [core] editor = code [filter "lfs"] smudge = git-lfs smudge -- %f process = git-lfs filter-process required = true clean = git-lfs clean -- %f [credential] helper = cache --timeout=3600

Slide 11

Slide 11 text

GitHub https://github.com

Slide 12

Slide 12 text

GitHub • Github provides hosting for software development version control using git • Owned by Microsoft • Offers free plans and pro and enterprise accounts • Offers unlimited private repositories to all plans, including free accounts

Slide 13

Slide 13 text

Software Repository • A software repository, or “repo” for short, is a storage location for software packages. • It is like a floder for you project • Contains all of your project's files and stores each file's revision history • You can share ownership of repository to other people

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

https://www.quora.com/How-is-Git-different-from-CVS Your repository is in server now!

Slide 16

Slide 16 text

Clone the repository to your computer git clone https://github.com/pohjus/shoppinglist Cloning into 'shoppinglist'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done.

Slide 17

Slide 17 text

Clone the repository to your computer cd shoppinglist/ ls -al drwxr-xr-x 4 pohjus staff 128 Apr 13 11:11 . drwxr-xr-x 3 pohjus staff 96 Apr 13 11:11 .. drwxr-xr-x 12 pohjus staff 384 Apr 13 11:11 .git -rw-r--r-- 1 pohjus staff 32 Apr 13 11:11 README.md

Slide 18

Slide 18 text

https://www.quora.com/How-is-Git-different-from-CVS Your repository is in your own computer also!

Slide 19

Slide 19 text

README.md file • The only file can be found now in three places • shoppinglist/README.md (working copy) • inside of .git/ folder (local repository) • In github server (server repository)

Slide 20

Slide 20 text

Workflow

Slide 21

Slide 21 text

Let's create new file with some content touch shopping-list.txt echo "- potato" >> shopping-list.txt cat shopping-list.txt - potato

Slide 22

Slide 22 text

Work directory . !"" README.md #"" shopping-list.txt

Slide 23

Slide 23 text

https://www.quora.com/How-is-Git-different-from-CVS the new file is just a workinc copy here

Slide 24

Slide 24 text

File States • File can be tracked or untracked • Untracked • git does not detect any changes to the file • Tracked • git follow if changes are made to the file

Slide 25

Slide 25 text

Checking state: git status git status On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add ..." to include in what will be committed) shopping-list.txt nothing added to commit but untracked files present (use "git add" to track) The new file is untracked!

Slide 26

Slide 26 text

File States • Untracked • Tracked • Unmodified – no changes to the file since last commit • Modified – changed since last commit • Staged – ready to be committed Tracked has sub states!

Slide 27

Slide 27 text

Changing state git add shopping-list.txt git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) new file: shopping-list.txt Let's add tracking to the new file The state is now staged (ready for commited)

Slide 28

Slide 28 text

Commiting to local repository git commit -m "shopping list added." [master f8f94d7] shopping list added. 1 file changed, 1 insertion(+) create mode 100644 shopping-list.txt

Slide 29

Slide 29 text

https://www.quora.com/How-is-Git-different-from-CVS shopping-list.txt the new file was committed to here: shopping-list.txt

Slide 30

Slide 30 text

Pushing to GitHub git push Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 12 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 308 bytes | 308.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/pohjus/shoppinglist c1d4598..f8f94d7 master -> master

Slide 31

Slide 31 text

https://www.quora.com/How-is-Git-different-from-CVS shopping-list.txt the new file was committed to here: shopping-list.txt the new file was committed to here: shopping-list.txt

Slide 32

Slide 32 text

the new file was committed to here: shopping-list.txt

Slide 33

Slide 33 text

Another Developer

Slide 34

Slide 34 text

Some other developer clones the repository

Slide 35

Slide 35 text

https://www.quora.com/How-is-Git-different-from-CVS shopping-list.txt the new file was committed to here: shopping-list.txt the new file was committed to here: shopping-list.txt And now the repository can be found in other PC shopping-list.txt

Slide 36

Slide 36 text

Let's change the shopping-list.txt Added the tomato here

Slide 37

Slide 37 text

git status The file is tracked: modified

Slide 38

Slide 38 text

File States • Untracked • Tracked • Unmodified – no changes to the file since last commit • Modified – changed since last commit • Staged – ready to be committed It is not ready to be committed yet!

Slide 39

Slide 39 text

Modified -> Staged Now it is staged and ready to be commited

Slide 40

Slide 40 text

Commit Now new version is in local repository

Slide 41

Slide 41 text

https://www.quora.com/How-is-Git-different-from-CVS - tomato - tomato - tomato - tomato - potato - tomato - potato

Slide 42

Slide 42 text

git push

Slide 43

Slide 43 text

https://www.quora.com/How-is-Git-different-from-CVS - tomato - tomato - tomato - potato - tomato - potato - tomato - potato

Slide 44

Slide 44 text

Github Mr Windows made an update

Slide 45

Slide 45 text

Back to Mr Mac User: pull git pull remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/pohjus/shoppinglist f8f94d7..4a37b3e master -> origin/master Updating f8f94d7..4a37b3e Fast-forward shopping-list.txt | 1 + 1 file changed, 1 insertion(+)

Slide 46

Slide 46 text

https://www.quora.com/How-is-Git-different-from-CVS - tomato - potato - tomato - potato - tomato - potato - tomato - potato - tomato - potato

Slide 47

Slide 47 text

Some Coding

Slide 48

Slide 48 text

Delete txt rm shopping-list.txt git add shopping-list.txt git commit -m "deleted shopping list." git push

Slide 49

Slide 49 text

Create new file import java.util.*; class App { public static void main(String [] args) { List items = List.of("tomato", "potato"); items.forEach(System.out::println); } }

Slide 50

Slide 50 text

git status git status On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add ..." to include in what will be committed) App.class App.java nothing added to commit but untracked files present (use "git add" to track) Do not track classes!

Slide 51

Slide 51 text

Create .gitignore cat .gitignore *.class

Slide 52

Slide 52 text

git status git status On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add ..." to include in what will be committed) .gitignore App.java nothing added to commit but untracked files present (use "git add" to track)

Slide 53

Slide 53 text

git add -A git add -A git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) new file: .gitignore new file: App.java

Slide 54

Slide 54 text

commit and push git commit -m "Create .gitignore and new Java file." [master a53b44e] Create .gitignore and new Java file. 2 files changed, 9 insertions(+) create mode 100644 .gitignore create mode 100644 App.java git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 12 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 494 bytes | 494.00 KiB/s, done. Total 4 (delta 0), reused 0 (delta 0) To https://github.com/pohjus/shoppinglist 16f8ac8..a53b44e master -> master

Slide 55

Slide 55 text

Example of .gitignore .DS_Store .idea/* *.iml target/* ...