0% found this document useful (0 votes)
113 views

Lemi Orhan Ergin: You Should Be Aware of

This document outlines 10 Git anti-patterns that developers should be aware of, including pushing commits immediately without organizing them first, having branches that live too long, using cherry-pick excessively to prepare releases, being unable to understand the commit graph, and having ambiguous commit messages. The document recommends committing early and often, perfecting work later, publishing changes once, and using templates to create better commit messages. It indicates that git rebase and git push --force can cause duplicate commits in the commit graph.

Uploaded by

gambess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

Lemi Orhan Ergin: You Should Be Aware of

This document outlines 10 Git anti-patterns that developers should be aware of, including pushing commits immediately without organizing them first, having branches that live too long, using cherry-pick excessively to prepare releases, being unable to understand the commit graph, and having ambiguous commit messages. The document recommends committing early and often, perfecting work later, publishing changes once, and using templates to create better commit messages. It indicates that git rebase and git push --force can cause duplicate commits in the commit graph.

Uploaded by

gambess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

10 GIT ANTI PATTERNS

YOU SHOULD BE AWARE OF

Lemi Orhan Ergin Agile Software Craftsman & Co-Founder, Craftbase


LEMi ORHAN ERGiN
agile software craftsman
co-founder @ craftbase
ex Sony, eBay, ACM, iyzico
founder & co-organizer of SCTurkey 

Turkish Software Craftsmanship Community

/lemiorhan
lemiorhanergin.com
@lemiorhan
Do you push every commit
just a!er you create ?
ANTIPATTERN DANGER

Do you push every commit


just a!er you create ?

TORTURING GIT BY PUSH ANTI-PATTERN


ANTIPATTERN DANGER

if all you do is commit and immediate push


you lose the opportunity to organize your commits
via reset, rebase, commit with amend safely
and you have to use force push at every time
you organize your commits

TORTURING GIT BY PUSH ANTI-PATTERN


are you brave enough to
jump to any commit ?
ANTIPATTERN DANGER

are you brave enough to


jump to any commit ?
Nope. Usually tests do not pass, the application does
not work, even the code does not compile in majority
of commits.

BROKEN TIME MACHINE ANTI-PATTERN


are you brave enough to
jump to any commit ?
Do you want me to
help you about
finding the last
commit that finalizes
the feature?

BROKEN TIME MACHINE ANTI-PATTERN


do you have
loooooong living
topic branches ?
ANTIPATTERN DANGER

do you have
loooooong living
topic branches ?

LONG LIVING BRANCHES ANTI-PATTERN


we
do you have me me
lco
rg to
loooooong living eh
ell
topic branches ?

LONG LIVING BRANCHES ANTI-PATTERN


do you use cherry-pick
to prepare releases ?
ANTIPATTERN DANGER

do you use cherry-pick


to prepare releases ?

CHERRY-PICK OVERDOSE ANTI-PATTERN


FEATURE 12
FEATURE 14

FEATURE 13
HEAD
master

TAG/v13

version 2.0

$ git cherry-pick Every-Single-Commit-We-Want-To-Deploy

CHERRY-PICK OVERDOSE ANTI-PATTERN


do you fully understand
when you read
the commit graph ?
ANTIPATTERN DANGER

do you fully understand


when you read
the commit graph ?

LOST IN COMMIT GRAPH ANTI-PATTERN


do you fully understand
when you read the commit graph ?
topic and shared branches, tracking branches, tags, HEADs, merge commits, reverted commits…

LOST IN COMMIT GRAPH ANTI-PATTERN


Cure?
Commit Early, Commit O!en
Perfect Later, Publish Once

PS: There are more than one way to achieve this


HEAD
TOPIC
Our very first step is
defining a strategy to
master keep branches short
ORIGIN/master
split your big feature into
mini shippable tasks
refactorings
tasks, like rest endpoints
red-green-refactor

each task will have a


STEP 0 branch, not a feature
HEAD
TOPIC

master

commit early
ORIGIN/master

commit o!en
no need to compile
no need for CI
it’s only for versioning

STEP 1 do not push


HEAD
TOPIC

master
ORIGIN/master

Sync source branch


with one simple command
STEP 2 $ git fetch origin master:master
HEAD
TOPIC

master
ORIGIN/master

Sync source branch


with one simple command
STEP 2 $ git fetch origin master:master
HEAD
TOPIC

master
ORIGIN/master

Get incoming change sets


from source to topic
branch via merge
STEP 3 $ git merge master
HEAD
TOPIC

master
ORIGIN/master

Get incoming change sets


from source to topic
branch via merge
STEP 3 $ git merge master
HEAD
TOPIC

master
ORIGIN/master

REGULARLY
Get incoming change sets
from source to topic
branch via merge
STEP 3 $ git merge master
HEAD
TOPIC

master
ORIGIN/master

REGULARLY
Get incoming change sets
from source to topic
branch via merge
STEP 3 $ git merge master
TOPIC

master
ORIGIN/master
HEAD

merge back to source


by squashing all commits
in topic branch

STEP 4
$ git checkout master
$ git merge --squash topic
TOPIC

master
ORIGIN/master
HEAD

Delete the topic branch


STEP 5 $ git branch -D topic
master
ORIGIN/master
HEAD

Delete the topic branch


STEP 5 $ git branch -D topic
master
ORIGIN/master
HEAD

Delete the topic branch


$ git branch -D topic

STEP 5 Now you can push


Deleting branches a!er
merge will make your
TRUNK-BASED commit graph readable
DEVELOPMENT Continuous Integration
let's make git king again validates master branch
continuously
Pull requests can be
Commit early & o!en Deliver frequently used to review code
perfect later, publish be prepared to send and to validate before
once philosophy every single commit merging back to master
Github Flow can be Scrum tasks are Feature flags should be
used to govern overall mapped to commits, used whenever possible
not stories
is it hard to learn
Git commands?
ANTIPATTERN DANGER

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


does each of your commit have
one special purpose?
or you commit anything you have changed
ANTIPATTERN DANGER

stop adding
every change
prevent commits from being big ball of muds

BIG BALL OF MUD ANTI-PATTERN


stop adding
every change
prevent commits from being big ball of muds

local change sets at JetBrains IDEs

BIG BALL OF MUD ANTI-PATTERN


stop adding every change
partial add : git add -p
do you really understand
what’s wri!en in
commit messages?
ANTIPATTERN DANGER

commit
$ git config --global commit.template ~/.git-commit-template.txt
$ git config --global commit.cleanup strip

messages # WHAT
# <issue id> (this commit will...) <subject>

are # WHY and HOW


# Explain why this change is being made

documents! # RELATED
# Provide links or keys to any relevant issues or other resources

use git commit #


#
REMEMBER
use lower case in the subject line
templates to #
#
start with a verb in imperative tone in the subject line
do not end the subject line with a period
create be!er #
#
separate subject from body with a blank line
use the body to explain what and why vs. how
commit messages # can use multiple lines with "-" for bullet points in body

AMBIGIOUS COMMIT MESSAGES ANTI-PATTERN


Which of the following commands can cause
duplicate commits in the commit graph?

A git rebase C git merge

B git push --force D git pull


ANTIPATTERN DANGER

Which of the following commands can cause


duplicate commits in the commit graph?

A git rebase C git merge

B git push --force D git pull

DUPLICATE COMMITS ANTI-PATTERN


REBASE & FORCE PUSH
master $ git rebase master
$ git push -f
c1 c2 c3 c4 c7

c5 c6

FIX
HEAD
LOCAL
master UPSTREAM
c1 c2 c3 c4 c7

c5 c6

FIX
REBASE & FORCE PUSH
master $ git rebase master
$ git push -f
c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
HEAD LOCAL
master UPSTREAM
c1 c2 c3 c4 c7

c5 c6

FIX
REBASE & FORCE PUSH
master $ git rebase master
$ git push -f
c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
HEAD LOCAL
master UPSTREAM
c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
PULL A FORCE-PUSHED BRANCH
master
$ git pull
c1 c2 c3 c4 c7

c5 c6

FIX
HEAD
LOCAL
master UPSTREAM
c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
PULL A FORCE-PUSHED BRANCH
master
$ git pull
c1 c2 c3 c4 c7

c5 c6 c5’
c5 c6’
c6

FIX ORIGIN/FIX
HEAD
LOCAL
master UPSTREAM
c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
PULL A FORCE-PUSHED BRANCH
master
$ git pull
c1 c2 c3 c4 c7

c5 c6 c5’
c5 c6’
c6

c8
LOCAL
ORIGIN/FIX

master FIX UPSTREAM


HEAD

c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
PULL WITH REBASE
master
$ git pull --rebase
c1 c2 c3 c4 c7

c5 c6

FIX
HEAD
LOCAL
master UPSTREAM
c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
PULL WITH REBASE
master
$ git pull --rebase
c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
HEAD LOCAL
master UPSTREAM
c1 c2 c3 c4 c7

c5’
c5 c6’
c6

FIX
1. TORTURING GIT BY PUSH 16. BRANCH CEMETERY
2. BROKEN TIME MACHINE 17. UNCONTROLLED POWER
3. LONG LIVING BRANCHES 18. WEB OF REPOSITORIES
4. TOO LATE TO VALIDATE 19. ORACLE SYNDROME
5. CHERRY-PICK OVERDOSE 20. WAITING FOR HACKERS
6. LOST IN COMMIT GRAPH 21. EVIL MERGE
7. BUTTON ADDICT 22. BRANCH OVERDOSE
8. TRASH HOUSE 23. CHUCKY THE COMMAND
9. BIG BALL OF MUD 24. NO HERO TO SAVE LIVES
10. AMBIGIOUS COMMIT MESSAGES 25. DUPLICATE COMMITS
11. ZOMBIE REBASE 26. BIG FAT COMMIT
12. CODE LOSING SYNDROME 27. CONFLICT-FOBIA
13. MESS UP WITH THE ROLLBACK 28. MERGE HELL
14. CENTRALIZED GIT 29. F*UCK UP WITH FORCE PUSH
15. MERGE FANATIC 30. LIVING AT DETACHED HEAD STATE
LET’S RECAP

what was really


happened at that time?
ANTIPATTERN DANGER
$ git checkout tags/v1.1
Note: checking out 'cecd95914'.
login
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. master

TAG/v1.1

HEAD

DETACHED HEAD STATE


login

master

TAG/v1.1

HEAD
my poor friend
worked for
3 long days
$ git checkout master

login

HEAD
master

TAG/v1.1

when he moved to
another branch, all
commits were gone
$ git reflog

login

HEAD
master

TAG/v1.1

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
$ git reflog

login

HEAD
master

d d a d 6 e
63 0 e w e are
h e o n
t earching for
TAG/v1.1 s

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
login

HEAD
master

TAG/v1.1

typofix

$ git branch typofix 630ddad6e


login

HEAD
master

TAG/v1.1

typofix

$ git branch typofix 630ddad6e

KEEP CALM, NOTHING WILL BE LOST


ANTIPATTERN DANGER
LEMi ORHAN ERGiN /lemiorhan
agile software craftsman lemiorhanergin.com
co-founder @ craftbase
@lemiorhan

thank you all!


Feedback: bit.ly/lemiorhan

You might also like