SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
(don’t fear)
the rebase
Ciao
I’m Giorgio Cefaro
Lead Software Engineer
at
@giorrrgio
GIT
“unpleasant, silly,
incompetent, stupid,
annoying, senile, elderly
or childish person.”
https://en.wikipedia.org/wiki/Git_(slang)
1.
git-help
Use it, read it, understand it
Thanks!
Any questions?
@giorrrgio
2.
git-rebase
Put your current branch commits on the top of the
upstream head.
git-rebase
Why not git-merge ?
■ If you merge frequently, lots of merge
commits will create pollution
■ Your commits in your current branch will
go down in the history
git-rebase under the hood
A git checkout master is executed
If you do not specify an upstream, the configured
upstream will be used. If no branch available in upstream,
rebase will abort.
Current changes are saved in a temporary area.
$ git rebase master
git-rebase under the hood
Current branch is reset to origin/master or, if --onto is
specified, to the specified branch.
Changes saved before are now applied on the top of the
new base, commit by commit.
$ git rebase master
Note: any commits with same textual changes already introduced in the upstream branch are
skipped (most of the times you can safely try to cherry pick something from another branch and
then let git remove the duplicates patches on a future rebase)
git-rebase under the hood
If no there are no conflicts during the rebase, you are
done.
Otherwise:
■ resolve the conflicts and git rebase --continue
■ skip the offending patch with git rebase --skip
■ abort the rebase with git rebase --abort
$ git rebase master
Note: aborting during a rebase is perfectly safe, you will go back to the exact point you were before
the rebase.
interactive git-rebase
Before applying your local commits, decide what to do
with each of it.
$ git rebase -i master
interactive git-rebase
Interactive rebase of the current branch starting from a
particular hash
$ git rebase -i <hash>^
Live coding!
git push --force
■ use it if you know what you are doing.
■ if you work on the same branch with other people, let
them know before.
■ before a push -f be sure that nobody has pushed
anything on the same branch before you and you will
probably be safe to do it.
■ It's hard that something is unrecoverable.
$ git push --force ⚠
forcing a push
■ Refuse to push a branch unless it is the state that we
expect; i.e. nobody has updated the branch upstream.
■ How? checking that the upstream ref is what we
expect.
■ does not work if the last time I updated with a git fetch
(the working tree is not altered)
$ git push --force-with-lease ⚠
“Hey Donald, where
are my commits ?”
git-reflog
■ Reflog is a mechanism to record when the tip of
branches are updated. This command is to manage the
information recorded in it.
■ You can take a look of what happened back in time
with a fine grain!
■ If something went wrong, just find the right hashbefore
the disaster and reset --hard <hash>
$ git reflog
git-reflog
■ Check what happened in the remote branch
■ Find the right hash before you push forced
$ git reflog show remotes/origin/master
Live coding!
Bonus git
tips!
3.
Bonus tips!
I bet you’ll find something you didn’t know here :-)
git-add
$ git add -p
■ Add files to the index interactively
■ Review your changes before adding them
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
interactive git-rebase with autosquash
$ git commit --fixup <hash>
■ Commit changes as a fixup to another commit
■ The commit message will start with “fixup! ”
■ Very useful for code reviews
interactive git-rebase with autosquash
$ git rebase -i --autosquash
■ Interactive rebase of current branch with automatic
fixup commits positioning (commits noted with a
“fixup!” prefix will be repositioned after their fixupped
commits)
git-pull
■ Pull “fast-forward only”: refuse to merge and exit with
a non-zero status unless the current HEAD is already
up-to-date or the merge can be resolved as a
fast-forward.
■ Alias it as git ff:
git config --global alias.ff pull --ff-only
$ git pull --ff-only
git-log
■ Format the logs in a more readable way
■ Add some ASCII art to represent branches
■ You can alias it as well for convenience
$ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s
%Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git-cherry-pick
■ Cherry pick a serie of consecutive commits to the
current branch
■ Mind the ^: without it you wouldn’t pick the first
commit
$ git cherry-pick <from_hash>^..<to_hash>
git-stash
■ Stash the uncommitted changes, including untracked
files with a proper name
$ git stash save -u “Ugly fix”
git-stash
■ Take the top of the stash and apply it to a new branch
$ git stash branch new-branch
git-stash
■ Apply a single file from the top of the stash
$ git checkout stash@{0} -- <file_path>
Thanks!
Any questions?
@giorrrgio

Mais conteúdo relacionado

Mais procurados

Improving your workflow with git
Improving your workflow with gitImproving your workflow with git
Improving your workflow with gitDídac Ríos
 
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]Cool Git Tricks (That I Learn When Things Go Badly) [1/2]
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]Carina C. Zona
 
Git introduction
Git introductionGit introduction
Git introductionmxamin
 
Git without github
Git without githubGit without github
Git without githubafayolle
 
How to make friends with git
How to make friends with gitHow to make friends with git
How to make friends with gitIlya Vorobiev
 
Using Git on the Command Line
Using Git on the Command LineUsing Git on the Command Line
Using Git on the Command LineBrian Richards
 

Mais procurados (7)

Improving your workflow with git
Improving your workflow with gitImproving your workflow with git
Improving your workflow with git
 
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]Cool Git Tricks (That I Learn When Things Go Badly) [1/2]
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]
 
Git Rebase vs Merge
Git Rebase vs MergeGit Rebase vs Merge
Git Rebase vs Merge
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git without github
Git without githubGit without github
Git without github
 
How to make friends with git
How to make friends with gitHow to make friends with git
How to make friends with git
 
Using Git on the Command Line
Using Git on the Command LineUsing Git on the Command Line
Using Git on the Command Line
 

Semelhante a Don't fear the rebase

How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get GitSusan Tan
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)Carlos Duarte do Nascimento
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221Shinho Kang
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of GitWayne Chen
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messesKatie Sylor-Miller
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With GitHoffman Lab
 
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a BossGit Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Bosstmacwilliam
 
slides.pdf
slides.pdfslides.pdf
slides.pdfvidsvagi
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use ItDaniel Kummer
 
Git Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it AgainGit Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it AgainLemi Orhan Ergin
 
Git workshop
Git workshopGit workshop
Git workshopRay Toal
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for GitJan Krag
 

Semelhante a Don't fear the rebase (20)

Ohh shit git
Ohh shit gitOhh shit git
Ohh shit git
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of Git
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With Git
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a BossGit Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
 
slides.pdf
slides.pdfslides.pdf
slides.pdf
 
slides.pdf
slides.pdfslides.pdf
slides.pdf
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Git Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it AgainGit Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it Again
 
Jedi Mind Tricks in Git
Jedi Mind Tricks in GitJedi Mind Tricks in Git
Jedi Mind Tricks in Git
 
Git
GitGit
Git
 
Git workshop
Git workshopGit workshop
Git workshop
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for Git
 

Mais de Giorgio Cefaro

Alexa, AWS lambda & wikidata (ITA)
Alexa, AWS lambda & wikidata (ITA)Alexa, AWS lambda & wikidata (ITA)
Alexa, AWS lambda & wikidata (ITA)Giorgio Cefaro
 
PHP object calisthenics
PHP object calisthenicsPHP object calisthenics
PHP object calisthenicsGiorgio Cefaro
 
Import golang; struct microservice - Codemotion Rome 2015
Import golang; struct microservice - Codemotion Rome 2015Import golang; struct microservice - Codemotion Rome 2015
Import golang; struct microservice - Codemotion Rome 2015Giorgio Cefaro
 
I came, I saw, I GO! - Golangit meetup @ Codemotion Rome 2014
I came, I saw, I GO! - Golangit meetup @ Codemotion Rome 2014I came, I saw, I GO! - Golangit meetup @ Codemotion Rome 2014
I came, I saw, I GO! - Golangit meetup @ Codemotion Rome 2014Giorgio Cefaro
 
Nanos gigantium humeris insidentes (design patterns inside symfony 2)
Nanos gigantium humeris insidentes (design patterns inside symfony 2)Nanos gigantium humeris insidentes (design patterns inside symfony 2)
Nanos gigantium humeris insidentes (design patterns inside symfony 2)Giorgio Cefaro
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridGiorgio Cefaro
 
High Performance Web Apps con PHP e Symfony 2
High Performance Web Apps con PHP  e Symfony 2High Performance Web Apps con PHP  e Symfony 2
High Performance Web Apps con PHP e Symfony 2Giorgio Cefaro
 
An introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developersAn introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developersGiorgio Cefaro
 
Netbeans e Xdebug per debugging e profiling di applicazioni PHP
Netbeans e Xdebug per debugging e profiling di applicazioni PHPNetbeans e Xdebug per debugging e profiling di applicazioni PHP
Netbeans e Xdebug per debugging e profiling di applicazioni PHPGiorgio Cefaro
 

Mais de Giorgio Cefaro (11)

Alexa, AWS lambda & wikidata (ITA)
Alexa, AWS lambda & wikidata (ITA)Alexa, AWS lambda & wikidata (ITA)
Alexa, AWS lambda & wikidata (ITA)
 
PHP object calisthenics
PHP object calisthenicsPHP object calisthenics
PHP object calisthenics
 
jsDay 2016 recap
jsDay 2016 recapjsDay 2016 recap
jsDay 2016 recap
 
Import golang; struct microservice - Codemotion Rome 2015
Import golang; struct microservice - Codemotion Rome 2015Import golang; struct microservice - Codemotion Rome 2015
Import golang; struct microservice - Codemotion Rome 2015
 
I came, I saw, I GO! - Golangit meetup @ Codemotion Rome 2014
I came, I saw, I GO! - Golangit meetup @ Codemotion Rome 2014I came, I saw, I GO! - Golangit meetup @ Codemotion Rome 2014
I came, I saw, I GO! - Golangit meetup @ Codemotion Rome 2014
 
Nanos gigantium humeris insidentes (design patterns inside symfony 2)
Nanos gigantium humeris insidentes (design patterns inside symfony 2)Nanos gigantium humeris insidentes (design patterns inside symfony 2)
Nanos gigantium humeris insidentes (design patterns inside symfony 2)
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
High Performance Web Apps con PHP e Symfony 2
High Performance Web Apps con PHP  e Symfony 2High Performance Web Apps con PHP  e Symfony 2
High Performance Web Apps con PHP e Symfony 2
 
From LAMP to LNNP
From LAMP to LNNPFrom LAMP to LNNP
From LAMP to LNNP
 
An introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developersAn introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developers
 
Netbeans e Xdebug per debugging e profiling di applicazioni PHP
Netbeans e Xdebug per debugging e profiling di applicazioni PHPNetbeans e Xdebug per debugging e profiling di applicazioni PHP
Netbeans e Xdebug per debugging e profiling di applicazioni PHP
 

Último

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 

Último (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 

Don't fear the rebase

  • 2. Ciao I’m Giorgio Cefaro Lead Software Engineer at @giorrrgio
  • 3. GIT
  • 4. “unpleasant, silly, incompetent, stupid, annoying, senile, elderly or childish person.” https://en.wikipedia.org/wiki/Git_(slang)
  • 5. 1. git-help Use it, read it, understand it
  • 7. 2. git-rebase Put your current branch commits on the top of the upstream head.
  • 8. git-rebase Why not git-merge ? ■ If you merge frequently, lots of merge commits will create pollution ■ Your commits in your current branch will go down in the history
  • 9. git-rebase under the hood A git checkout master is executed If you do not specify an upstream, the configured upstream will be used. If no branch available in upstream, rebase will abort. Current changes are saved in a temporary area. $ git rebase master
  • 10. git-rebase under the hood Current branch is reset to origin/master or, if --onto is specified, to the specified branch. Changes saved before are now applied on the top of the new base, commit by commit. $ git rebase master Note: any commits with same textual changes already introduced in the upstream branch are skipped (most of the times you can safely try to cherry pick something from another branch and then let git remove the duplicates patches on a future rebase)
  • 11. git-rebase under the hood If no there are no conflicts during the rebase, you are done. Otherwise: ■ resolve the conflicts and git rebase --continue ■ skip the offending patch with git rebase --skip ■ abort the rebase with git rebase --abort $ git rebase master Note: aborting during a rebase is perfectly safe, you will go back to the exact point you were before the rebase.
  • 12. interactive git-rebase Before applying your local commits, decide what to do with each of it. $ git rebase -i master
  • 13. interactive git-rebase Interactive rebase of the current branch starting from a particular hash $ git rebase -i <hash>^
  • 15. git push --force ■ use it if you know what you are doing. ■ if you work on the same branch with other people, let them know before. ■ before a push -f be sure that nobody has pushed anything on the same branch before you and you will probably be safe to do it. ■ It's hard that something is unrecoverable. $ git push --force ⚠
  • 16. forcing a push ■ Refuse to push a branch unless it is the state that we expect; i.e. nobody has updated the branch upstream. ■ How? checking that the upstream ref is what we expect. ■ does not work if the last time I updated with a git fetch (the working tree is not altered) $ git push --force-with-lease ⚠
  • 17. “Hey Donald, where are my commits ?”
  • 18.
  • 19. git-reflog ■ Reflog is a mechanism to record when the tip of branches are updated. This command is to manage the information recorded in it. ■ You can take a look of what happened back in time with a fine grain! ■ If something went wrong, just find the right hashbefore the disaster and reset --hard <hash> $ git reflog
  • 20. git-reflog ■ Check what happened in the remote branch ■ Find the right hash before you push forced $ git reflog show remotes/origin/master
  • 23. 3. Bonus tips! I bet you’ll find something you didn’t know here :-)
  • 24. git-add $ git add -p ■ Add files to the index interactively ■ Review your changes before adding them y - stage this hunk n - do not stage this hunk q - quit; do not stage this hunk or any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk or any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
  • 25. interactive git-rebase with autosquash $ git commit --fixup <hash> ■ Commit changes as a fixup to another commit ■ The commit message will start with “fixup! ” ■ Very useful for code reviews
  • 26. interactive git-rebase with autosquash $ git rebase -i --autosquash ■ Interactive rebase of current branch with automatic fixup commits positioning (commits noted with a “fixup!” prefix will be repositioned after their fixupped commits)
  • 27. git-pull ■ Pull “fast-forward only”: refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward. ■ Alias it as git ff: git config --global alias.ff pull --ff-only $ git pull --ff-only
  • 28. git-log ■ Format the logs in a more readable way ■ Add some ASCII art to represent branches ■ You can alias it as well for convenience $ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
  • 29. git-cherry-pick ■ Cherry pick a serie of consecutive commits to the current branch ■ Mind the ^: without it you wouldn’t pick the first commit $ git cherry-pick <from_hash>^..<to_hash>
  • 30. git-stash ■ Stash the uncommitted changes, including untracked files with a proper name $ git stash save -u “Ugly fix”
  • 31. git-stash ■ Take the top of the stash and apply it to a new branch $ git stash branch new-branch
  • 32. git-stash ■ Apply a single file from the top of the stash $ git checkout stash@{0} -- <file_path>