git

124
Matt Harasymczuk GIT introduction

Upload: matt-harasymczuk

Post on 17-Jan-2017

212 views

Category:

Software


0 download

TRANSCRIPT

Page 1: GIT

Matt Harasymczuk

GIT introduction

Page 2: GIT

Matt Harasymczuk

Page 3: GIT

Matt Harasymczuk

Page 4: GIT

Matt Harasymczuk

Page 5: GIT

Matt Harasymczuk

Page 6: GIT

Matt Harasymczuk

Key - Value

Page 7: GIT

Matt Harasymczuk

Branching is not the issue, the merging is...

Linus Torvalds

Page 8: GIT

Matt Harasymczuk

Page 9: GIT

Matt Harasymczuk

Page 10: GIT

Matt Harasymczuk

Page 11: GIT

Matt Harasymczuk

Page 12: GIT

Matt Harasymczuk

Page 13: GIT

Matt Harasymczuk

Page 14: GIT

Matt HarasymczukRename

track

discover

Page 15: GIT

Matt Harasymczuk

GIT hash

Page 16: GIT

Matt Harasymczuk

git remotes

• git ls-remote

• git gc --aggressive --prune=now

• git remote update --prune

• git remote -v

Page 17: GIT

Matt Harasymczuk

GitHub.com

• create accounts

• create repo

• protect branches

• add collaborators

• clone & touch .gitignore & push

• pull-request

Page 18: GIT

Matt Harasymczuk

GIT refs

• .git/HEAD

• .git/refs/heads/master

• .git/refs/heads/*

• .git/refs/remotes/*

• .git/refs/tags/*

• (HEAD detached at 44d11b0)

Page 19: GIT

Matt Harasymczuk

.git internals

• ~/.gitconfig

• .git/config

• git config multiple url

• .git/refs/*

• .git/HEAD

• .git/objects/*

• .git/objects/pack/

Page 20: GIT

Matt Harasymczuk

.gitconfig [alias]

• l = log --pretty=format:"%C(yellow)%h %ad%Cred%d %Creset%s%Cblue [%cn]" --decorate --date=short

• again = "!f() { git add -A && git status && git commit -m \"$(git log -1 --format='%s')\" && git push && git l -1; }; f"

• d = diff --cached HEAD^

Page 21: GIT

Matt Harasymczuk

.gitconfig[i18n]

commitencoding = UTF-8

logoutputencoding = UTF-8

[core]

eol = 'lf'

autocrlf = input

excludesfile = /Users/matt/.gitignore_global

[branch "master"]

rebase = true

[branch]

#autosetuprebase = always

[color]

ui = true

Page 22: GIT

Matt Harasymczuk

Page 23: GIT

Matt Harasymczuk

Page 24: GIT

Matt Harasymczuk

Page 25: GIT

Matt Harasymczuk

Page 26: GIT

Matt Harasymczuk

Page 27: GIT

Matt Harasymczuk

Scenariusz• github account

• ssh-keygen

• add ssh to profile (~/.ssh/id_rsa.pub)

• share repository access with people

• clone repository via ssh

• add file inazwisko.txt

• add user.email and user.name to gitconfig

• amend & commit & push

• pull request + uprawnienia + mergowanie

Page 28: GIT

Matt Harasymczuk

Rozpoczynanie pracy

• git init

• git init --bare

• git clone URL [dest dir]

• git clone file:///...

• git clone ssh://...

• git clone https://...

• git clone --recursive URL

Page 29: GIT

Matt Harasymczuk

git branch

• git branch

• git branch inazwisko

• git checkout inazwisko

• git checkout -tb origin/master

Page 30: GIT

Matt Harasymczuk

git reset

• git reset --hard

• git reset --soft

• git reset --mixed

Page 31: GIT

Matt Harasymczuk

git pull

• git fetch

• git merge or git rebase

Page 32: GIT

Matt Harasymczuk

git push

• git push

• git push --tags

• git push --all

• git push origin

• git push origin master

• git push origin master:inazwisko

• git push origin :inazwisko

Page 33: GIT

Matt Harasymczuk

git stash

• git stash [save]

• git stash list

• git stash pop vs. git stash apply

• git stash drop

• git stash clear

• konflikty przy git stash apply

Page 34: GIT

Matt Harasymczuk

git tag

• git tag -n1

• git tag --list

• git describe

• .git/refs/tags/*

• git push --tags

• git push origin <tag_name>

Page 35: GIT

Matt Harasymczuk

Page 36: GIT

Matt Harasymczuk

History Manipulation

Page 37: GIT

Matt HarasymczukMieszko I B. Chrobry Mieszko IIK.

Odnowiciel

Page 38: GIT

Matt HarasymczukMieszko I

B. Chrobry

Mieszko IIK.

Odnowiciel

Page 39: GIT

Matt HarasymczukMieszko I

B. Chrobry

Mieszko IIK.

Odnowiciel

Page 40: GIT

Matt HarasymczukMieszko I B. ChrobryMieszko IIK.

Odnowiciel

Page 41: GIT

Matt Harasymczuk

Remove sensitive data

FILENAME=”secret.txt”

git filter-branch--index-filter 'git rm --cached --ignore-unmatch $FILENAME'--prune-empty ----all

http://help.github.com/remove-sensitive-data/

Page 42: GIT

Matt Harasymczuk

Change user or emailgit filter-branch --commit-filter '

if [ "$GIT_COMMITTER_NAME" = "flastname" ]; then

GIT_COMMITTER_NAME="Firstname Lastname"; GIT_AUTHOR_NAME="Firstname Lastname"; GIT_COMMITTER_EMAIL="[email protected]"; GIT_AUTHOR_EMAIL="[email protected]"; git commit-tree "$@";

else

git commit-tree "$@";

fi' HEAD

Page 43: GIT

Matt Harasymczuk

cherry-picking

Page 44: GIT

Matt Harasymczuk

Page 45: GIT

Matt Harasymczuk

Page 46: GIT

Matt Harasymczuk

Page 47: GIT

Matt Harasymczuk

git merge

Page 48: GIT

Matt Harasymczuk

Page 49: GIT

Matt Harasymczuk

Page 50: GIT

Matt Harasymczuk

Page 51: GIT

Matt Harasymczuk

rebase

Page 52: GIT

Matt Harasymczuk

Page 53: GIT

Matt Harasymczuk

Page 54: GIT

Matt Harasymczuk

Page 55: GIT

Matt Harasymczuk

Page 56: GIT

Matt Harasymczuk

Page 57: GIT

Matt Harasymczuk

Page 58: GIT

Matt Harasymczuk

rebase vs. merge

Page 59: GIT

Matt Harasymczuk

Page 60: GIT

Matt Harasymczuk

git rebase -i

• p, pick = use commit

• r, reword = use commit, but edit the commit message

• e, edit = use commit, but stop for amending

• s, squash = use commit, but meld into previous commit

• f, fixup = like "squash", but discard this commit's log message

• x, exec = run command (the rest of the line) using shell

• d, drop = remove commit

Page 61: GIT

Matt Harasymczuk

squash

Page 62: GIT

Matt Harasymczuk

pushed repo rebase

• git push --force

Page 63: GIT

Matt Harasymczuk

GIT tools

Page 64: GIT

Matt Harasymczuk

Page 65: GIT

Matt Harasymczuk

Workflow

Page 66: GIT

Matt Harasymczuk

git pull --rebase

Page 67: GIT

Matt Harasymczuk

git add

Page 68: GIT

Matt Harasymczuk

git rm

Page 69: GIT

Matt Harasymczuk

git mv

Page 70: GIT

Matt Harasymczuk

git commit

Page 71: GIT

Matt Harasymczuk

Page 72: GIT

Matt Harasymczuk

git push

Page 73: GIT

Matt Harasymczuk

Page 74: GIT

Matt Harasymczuk

git log• git log --oneline

• git log --graph

• git log -5

• git log -15 --oneline --graph

• git log --format='%h %ae %s'

• git log --format='"%H", "%an", "%ae", "%ad", "%s"' --date=iso > ~/Desktop/commits.csv

• git log --format='%ad' --date=iso

• git log --format='%ae' |sort |uniq

Page 75: GIT

Matt Harasymczuk

• git reflog

Page 76: GIT

Matt Harasymczuk

git status

Page 77: GIT

Matt Harasymczuk

git show

Page 78: GIT

Matt Harasymczuk

# changes in working directorygit diff

# changes between commitsgit diff ac04c72..5968eb9

git diff HEAD^

Page 79: GIT

Matt Harasymczuk

git submodule• git submodule add [email protected]:AstroTech/workshop-git lib/git-docs

• git status

• cat .gitmodules

• git submodule init

• git submodule update

• git submodule rm lib/git-docs

• Update submodułów

• cd lib/git-docs

• git pull

• cd ..

• git status

• git commit

Page 80: GIT

Matt Harasymczuk

git subtree

Page 81: GIT

Matt Harasymczuk

git hooks

• .git/hooks/pre-commit

• chmod +x .git/hooks/pre-commit

• #!/bin/sh

• exit 0 # zmiana sie zapisze

• exit 1 # kod bledu, nie zakomituje sie

Page 82: GIT

Matt Harasymczukgit bisect and git blame

Page 83: GIT

Matt Harasymczuk

git rebase

• git rebase -i HEAD~3

• git rebase -i HEAD^^^

• git rebase -i HEAD ~~~

• git rebase -i --root

• (old version problem with rebase of first commit)

Page 84: GIT

Matt Harasymczuk

GIT gui tools

• gitk

• sourcetree

• msysgit

• tortoiseGIT

Page 85: GIT

Matt Harasymczuk

IDE

• Eclipse

• InteliJ• PyCharm

• Webstorm

• Rubymine

• NetBeans

Page 86: GIT

Matt Harasymczuk

GIT repo hosting - cloud

• Gitlab

• Bitbucket Cloud

• Github

Page 87: GIT

Matt Harasymczuk

GIT repo hosting - server

• Gitlab

• Bitbucket Server

• Github Enterprise

• Gitolite

• Gitblit

Page 88: GIT

Matt Harasymczuk

CI / CD

• circleCI

• travis

• bitbucket pipelines

Page 89: GIT

Matt Harasymczuk

ssh-keygen

• vim ~/.ssh/id_rsa.pub

[email protected]/hostname

Page 90: GIT

Matt Harasymczuk

GIT LFS

Page 91: GIT

Matt Harasymczuk

Strategies

Page 92: GIT

Matt Harasymczuk

Central Repository Model

Page 93: GIT

Matt Harasymczuk

Page 94: GIT

Matt Harasymczuk

Cherry-picking Model

Page 95: GIT

Matt Harasymczuk

Page 96: GIT

Matt Harasymczuk

Page 97: GIT

Matt Harasymczuk

Page 98: GIT

Matt Harasymczuk

Page 99: GIT

Matt Harasymczuk

Page 100: GIT

Matt Harasymczuk

Page 101: GIT

Matt Harasymczuk

Army Model

Page 102: GIT

Matt Harasymczuk

Page 103: GIT

Matt Harasymczuk

Page 104: GIT

Matt Harasymczuk

Page 105: GIT

Matt Harasymczuk

Page 106: GIT

Matt Harasymczuk

Page 107: GIT

Matt Harasymczuk

Modele pracy z GIT

Page 108: GIT

Matt Harasymczuk

GIT Flow

• https://github.com/nvie/gitflow

• http://nvie.com/posts/a-successful-git-branching-model/

• https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

Page 109: GIT

Matt Harasymczuk

Feature branching model

• https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow

Page 110: GIT

Matt Harasymczuk

Forking Workflow

• https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow

Page 111: GIT

Matt Harasymczuk

Usecase

Page 112: GIT

Matt Harasymczuk

allegro release

Page 113: GIT

Matt Harasymczuk

allegro test env

Page 114: GIT

Matt Harasymczuk

pull request

Page 115: GIT

Matt Harasymczuk

Markdown• # naglowek 1 poziomu

• ## naglowek 2 poziomu

• ### naglowek 3 poziomu

• [Opis](http://example.com/)

• ![Opis](http://example.com/img.jpg)

• `code`

• *em* i **strong**

• Tabelki

• Listy• numerowane

• nieuporządkowane

• zagnieżdżone

Page 116: GIT

Matt Harasymczuk

Przydatne URL

• https://github.com/AstroTech/workshop-git/

• https://www.atlassian.com/git/

• https://travis.org

• https://bitbucket.org

• http://git-scm.com

Page 117: GIT

Matt Harasymczuk

lolcommits

• lolcommits --enable

• lolcommits --disable

Page 118: GIT

Matt Harasymczuk

Conclusion

Page 119: GIT

Matt Harasymczuk

Why DVCS?

Page 120: GIT

Matt Harasymczuk

Why GIT?

Page 121: GIT

Matt Harasymczuk

Page 122: GIT

Matt Harasymczuk

Page 123: GIT

Matt Harasymczuk

Page 124: GIT

Matt Harasymczuk

Ask me about your problem :}