Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
GITANTI
PATTERNS
How To Mess Up With Git and Love It Again
LEMi ORHAN ERGiN
Agile Software Craftsman, iyzico
/lemiorhan
le...
DISCLOSURE
There is no formula for using git efficiently.
Opinions are my own. It means the opposites
might work perfectly...
git is powerful
but you have to know using it properly
Are you using git
if all you do is commit-push-pull
use dropbox instead
ANTIPATTERN DANGER
as if it is dropbox ?
1DROPBOX-...
learn how git works
no worries, I will cover how git behaves
the way it keeps
FILES & FOLDERS
working copy
staging area
objects database
repository
the way it keeps
REFERENCES
directe...
Source Code
Working Copy
you want to version changes
Source Code
Working Copy
$ git init
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
initializ...
Source Code
Working Copy
$ git init --bare
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Re...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
folder
folder
folder
file
file
file
$ git add .
preparing commits
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
$ git commit -m “initial commit”
commi!ing
folder
folder
folder
file
file
file
commit
branch
HEAD
For more details, refer ...
folder
folder
folder
file
file
file
commit
$ git commit -m “second commit”
commi!ing
folder
commit
branch
HEAD
folder
file...
folder
folder
folder
file
file
file
commit
$ git commit -m “third commit”
commi!ing
folder
commit
folder
file
folder
folde...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
folder
folder
folder
file
file
file
commit
folder
commit
folder
file
folder
folder
commit
branch
HEAD
file
For more detail...
folder
folder
folder
file
file
file
commit
folder
commit
folder
file
folder
folder
commit
branch
HEAD
file
For more detail...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
Object Database
.git Folder / Object Database
Cache
Staging Area / The Index
Remote
Upstream Repo / Remote Repo
Server
Sou...
are you brave enough to
jump to any commit ?
jump to a branch
create a branch from a commit
create a branch from a tag
ANT...
are you sure?
are you brave enough to
jump to any commit ?
do you have
loooooong living
topic branches ?
ANTIPATTERN DANGER
3LONG LIVING BRANCHES ANTI-PATTERN
do you have
loooooong living
topic branches ?
welcome to
merge hell
before merging
do you validate commits
back to source ?
ANTIPATTERN DANGER
code review, continuous integration, automated ...
before merging
do you validate commits
back to source ? areyou
sure?
merge and unmerge
do you o!en want to
just before releases ?
ANTIPATTERN DANGER
5CHERRY-PICK OBSSESSION ANTI-PATTERN
merge and unmerge
do you o!en want to
just before releases ?
master
HEAD
TAG/v13
version 14
$ git cherry-pick Every-Single...
the commit graph ?
do you fully understand
ANTIPATTERN DANGER
6DEATH ON COMMIT GRAPH ANTI-PATTERN
the commit graph ?
do you fully understand
topic and shared branches, tracking branches, tags, HEADs, merge commits, rever...
Cure?
Commit Early, Commit O"en
Perfect Later, Publish Once
STEP 0
split your big feature into
mini shippable tasks
master
HEAD
TOPIC
ORIGIN/master
refactorings
tasks, like rest endp...
STEP 1
commit early
commit o!en
no need to compile
no need for CI
it’s only for versioning
do not push
master
HEAD
TOPIC
O...
always pull with rebase
$ git pull --rebase origin master
to get forced pushes securely
to rebase your commits
master
HEAD...
always pull with rebase
$ git pull --rebase origin master
to get forced pushes securely
to rebase your commits
master
HEAD...
always pull with rebase
$ git pull --rebase origin master
to get forced pushes securely
to rebase your commits
master
HEAD...
always pull with rebase
$ git pull --rebase origin master
to get forced pushes securely
to rebase your commitsmaster
HEAD
...
perfect later
make it single commit
$ git reset HEAD~3
or
$ git rebase -i HEAD~3
HEAD
TOPIC
STEP 3
ORIGIN/master
tests are...
$ git reset HEAD~3 (then commit)
or
$ git rebase -i HEAD~3
HEAD
TOPIC
STEP 3
ORIGIN/master
perfect later
make it single co...
Use feature flags/toggles
HEAD
TOPIC
STEP 4
ORIGIN/master
if feature should be disabled
merge back to source
$ git checkout...
Use feature flags/toggles
master
HEAD
TOPIC
STEP 4
ORIGIN/master
if feature should be disabled
merge back to source
$ git c...
Continuous Integration
validates master branch
continuouslymaster
HEAD
TOPIC
ORIGIN/master
Pull requests can be
used to re...
use terminal
GUIs are prison balls of developers
it’s ok to use GUIs while checking diffs,
resolving conflicts and viewing c...
do not lose
take extra care while using hard reset
$ git reset --merge HEAD~
Use stash $ git stash save “updates local set...
TOPIC
HEAD
MASTER
$ git merge --squash fix
Squash commit -- not updating HEAD
Automatic merge went well; stopped before co...
long living branches with care
handle
TOPIC
HEAD
MASTER
$ git merge --squash fix
Squash commit -- not updating HEAD
Automa...
stop adding
prevent commits from being big ball of muds
every change
OMNIBUS BILL ANTI-PATTERN
10
ANTIPATTERN DANGER
stop adding
prevent commits from being big ball of muds
every change
local change sets at JetBrains IDEs
stop adding every change
partial add
messages
are
read!
# WHAT
# <issue id> (this commit will...) <subject>
# WHY and HOW
# Explain why this change is being ma...
messages
are
read!
use git commit
templates to
create be"er
commit messages
comtmi
by adding new commits ?
do you rollback your mistakes
ANTIPATTERN DANGER
12MESS UP WITH THE ROLLBACK ANTI-PATTERN
hard reset the merge commit
$ git reset --hard HEAD~
if you haven't pushed yet
HEAD
MASTER
Bug fıx
never force push
and change the history
if you already pushed to shared branch
Bug fıx
HEAD
MASTER
revert the merge commit
$ git revert 8f937c6 -m 1
if you already pushed
Bug fıx
HEAD
MASTER
is not the only method
pushing commits to server
ANTIPATTERN DANGER
for sharing your code
13CENTRALIZED GIT ANTI-PATTERN
Git Pong Pairing
$ git remote add personA <URL>
$ git fetch personA
$ git checkout personA/master
$ git checkout -b featur...
with the ones in source
branch ?
how do you sync your commits
ANTIPATTERN DANGER
14MERGE FANATIC ANTI-PATTERN
Bug fıx
ladder pa!ern
occurs when premature merge happens
HEAD
MASTER
FIX
master
c1 c2 c3 c4 c7
HEAD
c5 c6c5 c6
use rebase $ git rebase master
FIX
master
c1 c2 c3 c4 c7
HEAD
c5 c6c5 c6
use rebase $ git rebase master
FIX
master
c1 c2 c3 c4 c7
HEAD
c5 c6c5 c6
use rebase $ git rebase master
FIX
master
c1 c2 c3 c4 c7
HEAD
c5 c6c5 c6
use rebase $ git rebase master
c5
REPLAY #1
FIX
master
c1 c2 c3 c4 c7
HEAD
c5 c6c5 c6
use rebase $ git rebase master
c5
REPLAY #2
c6c6
FIX
master
c1 c2 c3 c4 c7
HEAD
c5 c6c5 c6
use rebase $ git rebase master
c5
REWIND
c6c6
FIX
master
c1 c2 c3 c4 c7
HEAD
use rebase $ git rebase master
c5
FINALIZE
c6c6
deleting branches?
are you scared of
ANTIPATTERN DANGER
15BRANCH CEMETERY ANTI-PATTERN
delete merged local branches
$ git branch --merged | grep -v '^* master$' | grep -v '^  master$' | xargs git branch -d
del...
delete all merged local branches
$ git branch --merged | grep -v '^* master$' | grep -v '^  master$' | xargs git branch -d...
wri!en in any form?
anyone can push any code
ANTIPATTERN DANGER
16UNCONTROLLED POWER ANTI-PATTERN
use
pre-receive
hooks
Depend on each other
Too many repositories
ANTIPATTERN DANGER
for sharing your code
17WEB OF REPOSITORIES ANTI-PATTERN
Mono Repository
System
Even though our services are still developed and deployed
independently, the code for all services ...
You can not do CI without using monorepos
- Xebia
“When you start a new project,” Potvin tells WIRED, “you
have a wealth o...
v1, v2, v3…
having branch for every release
ANTIPATTERN DANGER
18ORACLE SYNDROME ANTI-PATTERN
at the same time
Commit early & o"en
perfect later, publish
once philosophy
Deploy frequently
be prepared to send
every single commit
Newer...
to git repo
you pushed confidential info
ANTIPATTERN DANGER
19WAITING FOR HACKERS ANTI-PATTERN
Ref: https://help.github.com/articles/remove-sensitive-data/
Do you know what evil merge is?
ANTIPATTERN DANGER
20EVIL MERGE ANTI-PATTERN
do you use feature branches
when there is no product at all
ANTIPATTERN DANGER
21BRANCH OVERDOSE ANTI-PATTERN
use single branch
topic branches simply
make everything more
complex
Scared on using git commands
ANTIPATTERN DANGER
22CHUCKY THE COMMAND ANTI-PATTERN
push
add
dosya güncelleme
committed
Track ediliyor
untracked unmodified pushedmodified
staged
Staging Alanında Local Repoda ...
hard reset
committed
Track ediliyor
untracked unmodified pushedmodified
staged
Staging Alanında Local Repoda Uzak Repoda
add...
h"ps://github.com/lemiorhan/git-kata
no one knows git perfect
do you suffer?
ANTIPATTERN DANGER
23NO HERO TO SAVE LIVES ANTI-PATTERN
have a git-man
at least one developer
should expertise on git
for supporting the
others
Having duplicate commits
&
Having irrelevant merge commits
if you haven’t pushed yet
ANTIPATTERN DANGER
24DUPLICATE COMMIT...
UPSTREAM
LOCAL
master
c1 c2 c3 c4 c7
c5 c6c5 c6
FIX
HEAD
master
c1 c2 c3 c4 c7
c5 c6c5 c6
FIX
rebase and push
UPSTREAM
LOCAL
master
c1 c2 c3 c4 c7
c5 c6c5’ c6’
FIX
HEAD
master
c1 c2 c3 c4 c7
c5 c6c5 c6
FIX
$ git rebase master
rebase...
UPSTREAM
LOCAL
master
c1 c2 c3 c4 c7
c5 c6c5’ c6’
FIX
HEAD
master
c1 c2 c3 c4 c7
c5 c6c5’ c6’
FIX
$ git push -f
rebase and...
UPSTREAM
LOCAL
master
c1 c2 c3 c4 c7
c5 c6c5 c6
FIX
HEAD
master
c1 c2 c3 c4 c7
c5 c6c5’ c6’
FIX
pull rebased branch
UPSTREAM
LOCAL
master
c1 c2 c3 c4 c7
c5 c6c5’ c6’
FIX
HEAD
master
c1 c2 c3 c4 c7
c5 c6c5’ c6’
FIX
$ git pull --rebase
pull...
UPSTREAM
LOCAL
master
c1 c2 c3 c4 c7
c5 c6c5 c6
FIX
HEAD
master
c1 c2 c3 c4 c7
c5 c6c5’ c6’
FIX
c5 c6c5’ c6’
ORIGIN/FIX
$ ...
UPSTREAM
LOCAL
c1 c2 c3 c4 c7
c5 c6c5 c6
master
c1 c2 c3 c4 c7
c5 c6c5’ c6’
FIX
c5 c6c5’ c6’
c8
$ git pull
master
FIX
HEAD...
we commit when we have
something big
ANTIPATTERN DANGER
25BIG FAT COMMIT ANTI-PATTERN
use TDD style
whenever tests pass, commit
that makes you commit early and o!en
are you scared of using rebase?
ANTIPATTERN DANGER
26REBASE-FOBIA ANTI-PATTERN
rebasenot to merge your unpushed
commits with the fetched ones
use pull with
prepared by @lemiorhan
rebaseto get rebased c...
do you know when we get
conflicts and how to resolve it?
ANTIPATTERN DANGER
27CONFLICT-FOBIA ANTI-PATTERN
RECAP
what was really
happened at that time?
LET’S
master
TAG/v1.1
login
HEAD
DETACHED HEAD STATE
$ git checkout cecd95914
Note: checking out 'cecd95914'.
You are in 'detach...
master
TAG/v1.1
login
HEAD
DETACHED HEAD STATE
$ git rebase (and conflicts happen)
$ git checkout HEAD~2
$ git checkout 43...
master
TAG/v1.1
login
HEAD
poor little developer...
master
TAG/v1.1
login
HEAD
$ git checkout master
master
TAG/v1.1
login
HEAD
$ git reflog
aa67e3a2c HEAD@{0}: rebase finished: returning to refs/heads/fix/java-sql-Date-vio...
$ git reflog
630ddad6e
the one we are
searching for
master
TAG/v1.1
login
HEAD
aa67e3a2c HEAD@{0}: rebase finished: return...
master
typofix
TAG/v1.1
login
HEAD
$ git branch typofix 630ddad6e
master
typofix
TAG/v1.1
login
HEAD
$ git branch typofix 630ddad6e
KEEP CALM, NOTHING WILL BE LOST
LEMi ORHAN ERGiN
agile software craftsman @ iyzico
/lemiorhan
lemiorhanergin.com
@lemiorhan
ANTIPATTERN DANGER
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey Meetup
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey Meetup
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey Meetup
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey Meetup
Upcoming SlideShare
Loading in …5
×

Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey Meetup

3,586 views

Published on

These are the slides containing 28 anti-patterns in Git. I present these slides at 2 hours meetups and seminars.

Published in: Software
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey Meetup

  1. 1. GITANTI PATTERNS How To Mess Up With Git and Love It Again LEMi ORHAN ERGiN Agile Software Craftsman, iyzico /lemiorhan lemiorhanergin.com @lemiorhan 28 common git anti-patterns
  2. 2. DISCLOSURE There is no formula for using git efficiently. Opinions are my own. It means the opposites might work perfectly for your conditions.
  3. 3. git is powerful but you have to know using it properly
  4. 4. Are you using git if all you do is commit-push-pull use dropbox instead ANTIPATTERN DANGER as if it is dropbox ? 1DROPBOX-ISH GIT ANTI-PATTERN
  5. 5. learn how git works no worries, I will cover how git behaves
  6. 6. the way it keeps FILES & FOLDERS working copy staging area objects database repository the way it keeps REFERENCES directed acyclic graph keeping snapshots traversing graph branches, tags, heads git has 2 mechanisms
  7. 7. Source Code Working Copy you want to version changes
  8. 8. Source Code Working Copy $ git init Object Database .git Folder / Object Database Cache Staging Area / The Index initializing repo
  9. 9. Source Code Working Copy $ git init --bare Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server initializing bare repo
  10. 10. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git add . preparing commits
  11. 11. folder folder folder file file file $ git add . preparing commits
  12. 12. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git add . preparing commits
  13. 13. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git commit -m “initial commit” commi!ing
  14. 14. $ git commit -m “initial commit” commi!ing folder folder folder file file file commit branch HEAD For more details, refer to book Git Internals by Scott Chacon
  15. 15. folder folder folder file file file commit $ git commit -m “second commit” commi!ing folder commit branch HEAD folder file folder For more details, refer to book Git Internals by Scott Chacon
  16. 16. folder folder folder file file file commit $ git commit -m “third commit” commi!ing folder commit folder file folder folder commit branch HEAD file For more details, refer to book Git Internals by Scott Chacon
  17. 17. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git commit -m “initial commit” commi!ing
  18. 18. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git remote add origin http://upstream.repo $ git push -u origin master pushing to remote
  19. 19. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy new changes from others are pushed
  20. 20. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git fetch fetching changes
  21. 21. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git merge FETCHED_HEAD updating working copy
  22. 22. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git pull git fetch + git merge ge!ing changes to source code
  23. 23. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy want to update last commit
  24. 24. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git reset --soft $ git commit --amend/ so" reseting cannot be reached Only the cache for the commit you reseted is removed from staging area for your current branch
  25. 25. folder folder folder file file file commit folder commit folder file folder folder commit branch HEAD file For more details, refer to book Git Internals by Scott Chacon $ git reset --soft $ git commit --amend/ so" reseting
  26. 26. folder folder folder file file file commit folder commit folder file folder folder commit branch HEAD file For more details, refer to book Git Internals by Scott Chacon $ git reset --soft $ git commit --amend/ so" reseting
  27. 27. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy want to squash or change last commits
  28. 28. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git reset --mixed mixed reseting cannot be reached entries for commits, files and folders are removed from staging area
  29. 29. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy want to get rid of last commits
  30. 30. Object Database .git Folder / Object Database Cache Staging Area / The Index Remote Upstream Repo / Remote Repo Server Source Code Working Copy $ git reset --hard hard reseting cannot be reached removed from staging area removed from working copy
  31. 31. are you brave enough to jump to any commit ? jump to a branch create a branch from a commit create a branch from a tag ANTIPATTERN DANGER $ git checkout feature/PA-121 $ git checkout -b fix/missing-sign-parameter 2449be8 $ git checkout -b hotfix/v1.1 tags/v1 2BROKEN TIME MACHINE ANTI-PATTERN
  32. 32. are you sure? are you brave enough to jump to any commit ?
  33. 33. do you have loooooong living topic branches ? ANTIPATTERN DANGER 3LONG LIVING BRANCHES ANTI-PATTERN
  34. 34. do you have loooooong living topic branches ? welcome to merge hell
  35. 35. before merging do you validate commits back to source ? ANTIPATTERN DANGER code review, continuous integration, automated testing… 4TOO LATE TO VALIDATE ANTI-PATTERN
  36. 36. before merging do you validate commits back to source ? areyou sure?
  37. 37. merge and unmerge do you o!en want to just before releases ? ANTIPATTERN DANGER 5CHERRY-PICK OBSSESSION ANTI-PATTERN
  38. 38. merge and unmerge do you o!en want to just before releases ? master HEAD TAG/v13 version 14 $ git cherry-pick Every-Single-Commit-We-Want-To-Deploy
  39. 39. the commit graph ? do you fully understand ANTIPATTERN DANGER 6DEATH ON COMMIT GRAPH ANTI-PATTERN
  40. 40. the commit graph ? do you fully understand topic and shared branches, tracking branches, tags, HEADs, merge commits, reverted commits…
  41. 41. Cure?
  42. 42. Commit Early, Commit O"en Perfect Later, Publish Once
  43. 43. STEP 0 split your big feature into mini shippable tasks master HEAD TOPIC ORIGIN/master refactorings tasks, like rest endpoints testable, deployable each task will have a branch, not a feature
  44. 44. STEP 1 commit early commit o!en no need to compile no need for CI it’s only for versioning do not push master HEAD TOPIC ORIGIN/master
  45. 45. always pull with rebase $ git pull --rebase origin master to get forced pushes securely to rebase your commits master HEAD TOPIC STEP 2 ORIGIN/master
  46. 46. always pull with rebase $ git pull --rebase origin master to get forced pushes securely to rebase your commits master HEAD TOPIC STEP 2 ORIGIN/master
  47. 47. always pull with rebase $ git pull --rebase origin master to get forced pushes securely to rebase your commits master HEAD TOPIC STEP 2 ORIGIN/master if you branch is pushed already $ git push -f
  48. 48. always pull with rebase $ git pull --rebase origin master to get forced pushes securely to rebase your commitsmaster HEAD TOPIC STEP 2 ORIGIN/master if you branch is pushed already $ git push -f Sync source branch a!erwards $ git fetch origin master:master
  49. 49. perfect later make it single commit $ git reset HEAD~3 or $ git rebase -i HEAD~3 HEAD TOPIC STEP 3 ORIGIN/master tests are passing app is working code is reviewed (*) master
  50. 50. $ git reset HEAD~3 (then commit) or $ git rebase -i HEAD~3 HEAD TOPIC STEP 3 ORIGIN/master perfect later make it single commit tests are passing app is working code is reviewed (*) master
  51. 51. Use feature flags/toggles HEAD TOPIC STEP 4 ORIGIN/master if feature should be disabled merge back to source $ git checkout master $ git merge topic master
  52. 52. Use feature flags/toggles master HEAD TOPIC STEP 4 ORIGIN/master if feature should be disabled merge back to source $ git checkout master $ git merge topic
  53. 53. Continuous Integration validates master branch continuouslymaster HEAD TOPIC ORIGIN/master Pull requests can be used to review code and to validate before merging back to master Scrum tasks are mapped to commits, not stories Github Flow can be used to govern overall TAMING THE POWER OF GIT make git the king again Feature flags should be used whenever possible Commit early & o"en perfect later, publish once philosophy Deliver frequently be prepared to send every single commit Deleting branches a"er merge will make your commit graph readable
  54. 54. use terminal GUIs are prison balls of developers it’s ok to use GUIs while checking diffs, resolving conflicts and viewing commit graph BUTTON ADDICT ANTI-PATTERN 7 ANTIPATTERN DANGER
  55. 55. do not lose take extra care while using hard reset $ git reset --merge HEAD~ Use stash $ git stash save “updates local settings to keep db safe” $ git reset --hard HEAD~ $ git stash apply stash@{0} Create a new branch $ git checkout -b feature/PA-121 $ git add settings.xml $ git commit -m “adds new settings config” Use hard reset with merge and commit into it uncommited changes CODE LOSING SYNDROME ANTI-PATTERN 8 ANTIPATTERN DANGER
  56. 56. TOPIC HEAD MASTER $ git merge --squash fix Squash commit -- not updating HEAD Automatic merge went well; stopped before committing as requested $ git add . $ git commit -m “adds a feature” $ git branch -D topic TRASH HOUSE ANTI-PATTERN 9 long living branches with care handle ANTIPATTERN DANGER Squash all commits in your topic branch and 
 make them available in working copy
  57. 57. long living branches with care handle TOPIC HEAD MASTER $ git merge --squash fix Squash commit -- not updating HEAD Automatic merge went well; stopped before committing as requested $ git add . $ git commit -m “adds a feature” $ git branch -D topic Squash all commits in your topic branch and 
 make them available in working copy
  58. 58. stop adding prevent commits from being big ball of muds every change OMNIBUS BILL ANTI-PATTERN 10 ANTIPATTERN DANGER
  59. 59. stop adding prevent commits from being big ball of muds every change local change sets at JetBrains IDEs
  60. 60. stop adding every change partial add
  61. 61. messages are read! # WHAT # <issue id> (this commit will...) <subject> # WHY and HOW # Explain why this change is being made # RELATED # Provide links or keys to any relevant issues or other resources # REMEMBER # use lower case in the subject line # start with a verb in imperative tone in the subject line # do not end the subject line with a period # separate subject from body with a blank line # use the body to explain what and why vs. how # can use multiple lines with "-" for bullet points in body $ git config --global commit.template ~/.git-commit-template.txt $ git config --global commit.cleanup strip use git commit templates to create be"er commit messages comtmi F*CKING COMMIT MESSAGES ANTI-PATTERN 11 ANTIPATTERN DANGER
  62. 62. messages are read! use git commit templates to create be"er commit messages comtmi
  63. 63. by adding new commits ? do you rollback your mistakes ANTIPATTERN DANGER 12MESS UP WITH THE ROLLBACK ANTI-PATTERN
  64. 64. hard reset the merge commit $ git reset --hard HEAD~ if you haven't pushed yet HEAD MASTER Bug fıx
  65. 65. never force push and change the history if you already pushed to shared branch Bug fıx HEAD MASTER
  66. 66. revert the merge commit $ git revert 8f937c6 -m 1 if you already pushed Bug fıx HEAD MASTER
  67. 67. is not the only method pushing commits to server ANTIPATTERN DANGER for sharing your code 13CENTRALIZED GIT ANTI-PATTERN
  68. 68. Git Pong Pairing $ git remote add personA <URL> $ git fetch personA $ git checkout personA/master $ git checkout -b feature/PA-231 add your changes and commit $ git push personA feature/PA-231 A B $ git checkout feature/PA-231 add your changes and commit $ git pull personA feature/PA-231
  69. 69. with the ones in source branch ? how do you sync your commits ANTIPATTERN DANGER 14MERGE FANATIC ANTI-PATTERN
  70. 70. Bug fıx ladder pa!ern occurs when premature merge happens HEAD MASTER
  71. 71. FIX master c1 c2 c3 c4 c7 HEAD c5 c6c5 c6 use rebase $ git rebase master
  72. 72. FIX master c1 c2 c3 c4 c7 HEAD c5 c6c5 c6 use rebase $ git rebase master
  73. 73. FIX master c1 c2 c3 c4 c7 HEAD c5 c6c5 c6 use rebase $ git rebase master
  74. 74. FIX master c1 c2 c3 c4 c7 HEAD c5 c6c5 c6 use rebase $ git rebase master c5 REPLAY #1
  75. 75. FIX master c1 c2 c3 c4 c7 HEAD c5 c6c5 c6 use rebase $ git rebase master c5 REPLAY #2 c6c6
  76. 76. FIX master c1 c2 c3 c4 c7 HEAD c5 c6c5 c6 use rebase $ git rebase master c5 REWIND c6c6
  77. 77. FIX master c1 c2 c3 c4 c7 HEAD use rebase $ git rebase master c5 FINALIZE c6c6
  78. 78. deleting branches? are you scared of ANTIPATTERN DANGER 15BRANCH CEMETERY ANTI-PATTERN
  79. 79. delete merged local branches $ git branch --merged | grep -v '^* master$' | grep -v '^  master$' | xargs git branch -d delete remote branches $ git branch -r --merged | grep -v master | sed 's/origin///' | xargs -n 1 git push --delete origin
  80. 80. delete all merged local branches $ git branch --merged | grep -v '^* master$' | grep -v '^  master$' | xargs git branch -d delete all merged remote branches $ git branch -r --merged | grep -v master | sed 's/origin///' | xargs -n 1 git push --delete origin
  81. 81. wri!en in any form? anyone can push any code ANTIPATTERN DANGER 16UNCONTROLLED POWER ANTI-PATTERN
  82. 82. use pre-receive hooks
  83. 83. Depend on each other Too many repositories ANTIPATTERN DANGER for sharing your code 17WEB OF REPOSITORIES ANTI-PATTERN
  84. 84. Mono Repository System Even though our services are still developed and deployed independently, the code for all services lives in one repository The repository contains more than one logical project (e.g. an iOS client and a web-application) These projects are most likely unrelated, loosely connected or can be connected by other means (e.g via dependency management tools) Twi#er, Facebook, Google, Digital Ocean, Foursquare, Etsy, Shippable, Plataformatec, Ravelin
  85. 85. You can not do CI without using monorepos - Xebia “When you start a new project,” Potvin tells WIRED, “you have a wealth of libraries already available to you. Almost everything has already been done.” - Rachel Potvin, Engineering Manager at Google Our productivity has increased at least 5x. - Shippable
  86. 86. v1, v2, v3… having branch for every release ANTIPATTERN DANGER 18ORACLE SYNDROME ANTI-PATTERN at the same time
  87. 87. Commit early & o"en perfect later, publish once philosophy Deploy frequently be prepared to send every single commit Newer keep release branches for a long time master branch should be enough for all your needs
  88. 88. to git repo you pushed confidential info ANTIPATTERN DANGER 19WAITING FOR HACKERS ANTI-PATTERN
  89. 89. Ref: https://help.github.com/articles/remove-sensitive-data/
  90. 90. Do you know what evil merge is? ANTIPATTERN DANGER 20EVIL MERGE ANTI-PATTERN
  91. 91. do you use feature branches when there is no product at all ANTIPATTERN DANGER 21BRANCH OVERDOSE ANTI-PATTERN
  92. 92. use single branch topic branches simply make everything more complex
  93. 93. Scared on using git commands ANTIPATTERN DANGER 22CHUCKY THE COMMAND ANTI-PATTERN
  94. 94. push add dosya güncelleme committed Track ediliyor untracked unmodified pushedmodified staged Staging Alanında Local Repoda Uzak Repoda added add commitcommit
  95. 95. hard reset committed Track ediliyor untracked unmodified pushedmodified staged Staging Alanında Local Repoda Uzak Repoda added hard reset hard reset mixed reset mixed reset soft reset rm --cached rm x
  96. 96. h"ps://github.com/lemiorhan/git-kata
  97. 97. no one knows git perfect do you suffer? ANTIPATTERN DANGER 23NO HERO TO SAVE LIVES ANTI-PATTERN
  98. 98. have a git-man at least one developer should expertise on git for supporting the others
  99. 99. Having duplicate commits & Having irrelevant merge commits if you haven’t pushed yet ANTIPATTERN DANGER 24DUPLICATE COMMITS ANTI-PATTERN
  100. 100. UPSTREAM LOCAL master c1 c2 c3 c4 c7 c5 c6c5 c6 FIX HEAD master c1 c2 c3 c4 c7 c5 c6c5 c6 FIX rebase and push
  101. 101. UPSTREAM LOCAL master c1 c2 c3 c4 c7 c5 c6c5’ c6’ FIX HEAD master c1 c2 c3 c4 c7 c5 c6c5 c6 FIX $ git rebase master rebase and push
  102. 102. UPSTREAM LOCAL master c1 c2 c3 c4 c7 c5 c6c5’ c6’ FIX HEAD master c1 c2 c3 c4 c7 c5 c6c5’ c6’ FIX $ git push -f rebase and push
  103. 103. UPSTREAM LOCAL master c1 c2 c3 c4 c7 c5 c6c5 c6 FIX HEAD master c1 c2 c3 c4 c7 c5 c6c5’ c6’ FIX pull rebased branch
  104. 104. UPSTREAM LOCAL master c1 c2 c3 c4 c7 c5 c6c5’ c6’ FIX HEAD master c1 c2 c3 c4 c7 c5 c6c5’ c6’ FIX $ git pull --rebase pull rebased branch
  105. 105. UPSTREAM LOCAL master c1 c2 c3 c4 c7 c5 c6c5 c6 FIX HEAD master c1 c2 c3 c4 c7 c5 c6c5’ c6’ FIX c5 c6c5’ c6’ ORIGIN/FIX $ git pull pull rebased branch:(
  106. 106. UPSTREAM LOCAL c1 c2 c3 c4 c7 c5 c6c5 c6 master c1 c2 c3 c4 c7 c5 c6c5’ c6’ FIX c5 c6c5’ c6’ c8 $ git pull master FIX HEAD ORIGIN/FIX pull rebased branch:(
  107. 107. we commit when we have something big ANTIPATTERN DANGER 25BIG FAT COMMIT ANTI-PATTERN
  108. 108. use TDD style whenever tests pass, commit that makes you commit early and o!en
  109. 109. are you scared of using rebase? ANTIPATTERN DANGER 26REBASE-FOBIA ANTI-PATTERN
  110. 110. rebasenot to merge your unpushed commits with the fetched ones use pull with prepared by @lemiorhan rebaseto get rebased commits from upstream safely use pull with REBASEfeature branches to integrate into public branches that you pushed or that you pulled from another person Never use Rebase USE
  111. 111. do you know when we get conflicts and how to resolve it? ANTIPATTERN DANGER 27CONFLICT-FOBIA ANTI-PATTERN
  112. 112. RECAP what was really happened at that time? LET’S
  113. 113. master TAG/v1.1 login HEAD DETACHED HEAD STATE $ git checkout cecd95914 Note: checking out 'cecd95914'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. LIVING AT DETACHED HEAD STATE ANTI-PATTERN 28 ANTIPATTERN DANGER
  114. 114. master TAG/v1.1 login HEAD DETACHED HEAD STATE $ git rebase (and conflicts happen) $ git checkout HEAD~2 $ git checkout 43e3ab01 $ git checkout tags/v1.1 WHEN IT HAPPENS
  115. 115. master TAG/v1.1 login HEAD poor little developer...
  116. 116. master TAG/v1.1 login HEAD $ git checkout master
  117. 117. master TAG/v1.1 login HEAD $ git reflog aa67e3a2c HEAD@{0}: rebase finished: returning to refs/heads/fix/java-sql-Date-violates-LSR aa67e3a2c HEAD@{1}: rebase: fixes UnsupportedOperationException while calling toIstant() method of java.sql.Date a45f3c4e5 HEAD@{2}: rebase: checkout develop 630ddad6e HEAD@{3}: checkout: moving from develop to fix/java-sql-Date-violates-LSR b26cf7a1a HEAD@{4}: rebase: checkout develop 630ddad6e HEAD@{5}: checkout: moving from develop to fix/java-sql-Date-violates-LSR b26cf7a1a HEAD@{6}: pull: Fast-forward 8b59f8f50 HEAD@{7}: checkout: moving from fix/java-sql-Date-violates-LSR to develop
  118. 118. $ git reflog 630ddad6e the one we are searching for master TAG/v1.1 login HEAD aa67e3a2c HEAD@{0}: rebase finished: returning to refs/heads/fix/java-sql-Date-violates-LSR aa67e3a2c HEAD@{1}: rebase: fixes UnsupportedOperationException while calling toIstant() method of java.sql.Date a45f3c4e5 HEAD@{2}: rebase: checkout develop 630ddad6e HEAD@{3}: checkout: moving from develop to fix/java-sql-Date-violates-LSR b26cf7a1a HEAD@{4}: rebase: checkout develop 630ddad6e HEAD@{5}: checkout: moving from develop to fix/java-sql-Date-violates-LSR b26cf7a1a HEAD@{6}: pull: Fast-forward 8b59f8f50 HEAD@{7}: checkout: moving from fix/java-sql-Date-violates-LSR to develop
  119. 119. master typofix TAG/v1.1 login HEAD $ git branch typofix 630ddad6e
  120. 120. master typofix TAG/v1.1 login HEAD $ git branch typofix 630ddad6e KEEP CALM, NOTHING WILL BE LOST
  121. 121. LEMi ORHAN ERGiN agile software craftsman @ iyzico /lemiorhan lemiorhanergin.com @lemiorhan ANTIPATTERN DANGER

×