git
TRANSCRIPT
Matt Harasymczuk
GIT introduction
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Key - Value
Matt Harasymczuk
Branching is not the issue, the merging is...
Linus Torvalds
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt HarasymczukRename
track
discover
Matt Harasymczuk
GIT hash
Matt Harasymczuk
git remotes
• git ls-remote
• git gc --aggressive --prune=now
• git remote update --prune
• git remote -v
Matt Harasymczuk
GitHub.com
• create accounts
• create repo
• protect branches
• add collaborators
• clone & touch .gitignore & push
• pull-request
Matt Harasymczuk
GIT refs
• .git/HEAD
• .git/refs/heads/master
• .git/refs/heads/*
• .git/refs/remotes/*
• .git/refs/tags/*
• (HEAD detached at 44d11b0)
Matt Harasymczuk
.git internals
• ~/.gitconfig
• .git/config
• git config multiple url
• .git/refs/*
• .git/HEAD
• .git/objects/*
• .git/objects/pack/
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^
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
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
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
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
Matt Harasymczuk
git branch
• git branch
• git branch inazwisko
• git checkout inazwisko
• git checkout -tb origin/master
Matt Harasymczuk
git reset
• git reset --hard
• git reset --soft
• git reset --mixed
Matt Harasymczuk
git pull
• git fetch
• git merge or git rebase
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
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
Matt Harasymczuk
git tag
• git tag -n1
• git tag --list
• git describe
• .git/refs/tags/*
• git push --tags
• git push origin <tag_name>
Matt Harasymczuk
Matt Harasymczuk
History Manipulation
Matt HarasymczukMieszko I B. Chrobry Mieszko IIK.
Odnowiciel
Matt HarasymczukMieszko I
B. Chrobry
Mieszko IIK.
Odnowiciel
Matt HarasymczukMieszko I
B. Chrobry
Mieszko IIK.
Odnowiciel
Matt HarasymczukMieszko I B. ChrobryMieszko IIK.
Odnowiciel
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/
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
Matt Harasymczuk
cherry-picking
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
git merge
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
rebase
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
rebase vs. merge
Matt Harasymczuk
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
Matt Harasymczuk
squash
Matt Harasymczuk
pushed repo rebase
• git push --force
Matt Harasymczuk
GIT tools
Matt Harasymczuk
Matt Harasymczuk
Workflow
Matt Harasymczuk
git pull --rebase
Matt Harasymczuk
git add
Matt Harasymczuk
git rm
Matt Harasymczuk
git mv
Matt Harasymczuk
git commit
Matt Harasymczuk
Matt Harasymczuk
git push
Matt Harasymczuk
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
Matt Harasymczuk
• git reflog
Matt Harasymczuk
git status
Matt Harasymczuk
git show
Matt Harasymczuk
# changes in working directorygit diff
# changes between commitsgit diff ac04c72..5968eb9
git diff HEAD^
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
Matt Harasymczuk
git subtree
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
Matt Harasymczukgit bisect and git blame
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)
Matt Harasymczuk
GIT gui tools
• gitk
• sourcetree
• msysgit
• tortoiseGIT
Matt Harasymczuk
IDE
• Eclipse
• InteliJ• PyCharm
• Webstorm
• Rubymine
• NetBeans
Matt Harasymczuk
GIT repo hosting - cloud
• Gitlab
• Bitbucket Cloud
• Github
Matt Harasymczuk
GIT repo hosting - server
• Gitlab
• Bitbucket Server
• Github Enterprise
• Gitolite
• Gitblit
Matt Harasymczuk
CI / CD
• circleCI
• travis
• bitbucket pipelines
Matt Harasymczuk
GIT LFS
Matt Harasymczuk
Strategies
Matt Harasymczuk
Central Repository Model
Matt Harasymczuk
Matt Harasymczuk
Cherry-picking Model
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Army Model
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Modele pracy z 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
Matt Harasymczuk
Feature branching model
• https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow
Matt Harasymczuk
Forking Workflow
• https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow
Matt Harasymczuk
Usecase
Matt Harasymczuk
allegro release
Matt Harasymczuk
allegro test env
Matt Harasymczuk
pull request
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
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
Matt Harasymczuk
lolcommits
• lolcommits --enable
• lolcommits --disable
Matt Harasymczuk
Conclusion
Matt Harasymczuk
Why DVCS?
Matt Harasymczuk
Why GIT?
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Matt Harasymczuk
Ask me about your problem :}