SlideShare a Scribd company logo
federico.panini@fazland.com - CTO
Git in Pills
GIT Stashing
federico.panini@fazland.com - CTO
Git-Stash
save your work during work :)
federico.panini@fazland.com - CTO
The problem
When your working on a ticket to solve a bug or to implement a new feature,
frequently happens that you need to switch to another branch for solving a
problem that has occurred. So what to do ? Your actual work is in a messy state
you have new files, uncommitted ones …
Git-Stash
save your work during work :)
federico.panini@fazland.com - CTO
You could commit your amends and switch to the other branch for solve a bug:
DON’T DO IT!
You’ll loose all of the informations about your progress and also you’re storing a
commit with inconsistent code.
Git-Stash
save your work during work :)
federico.panini@fazland.com - CTO
How can I leave the state of my current branch clean, and switching to another
branch ?
use GIT STASH
Using git stash will allow you to maintain the dirty state of your current working
directory and saves it on a stack of unfinished changes that you can reapply
at any time.
Git-Stash
how to use it ? - stash p. 1
federico.panini@fazland.com - CTO
Stashing your current files is easy and simple: in your directory where messy
files are type:
$ git status
# On branch feature/610_i18N_de_ro
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: routing_de.yml
# modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php
# modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
#
# modified: scripts/crontab
#
You’ll see a list of unstaged files.
Git-Stash
how to use it ? - stash p. 2
federico.panini@fazland.com - CTO
Stashing your current files is easy and simple: in your directory where messy
files are now type:
$ git stash
Saved working directory and index state 
"WIP on feature/610_i18N_de_ro: 049d078 added the index file"
HEAD is now at 049d078 added the index file
(To restore them type "git stash apply")
Now your working directory is clear
$ git status
# On branch feature/610_i18N_de_ro
nothing to commit, working directory clean
at this point you can freely switch to another branch do whatever you need to
do to fix bugs or implement new feature
Git-Stash
how to use it ? - stash p. 3
federico.panini@fazland.com - CTO
Where are your stashed files now ?
$ git stash list
stash@{0}: WIP on feature/610_i18N_de_ro: 049d078 added the index file
stash@{1}: WIP on feature/610_i18N_de_ro: c264051 Revert "added file_size"
stash@{2}: WIP on feature/610_i18N_de_ro: 21d80a5 added number to log
You can see a list of stashes and the first one (stash{0}) is the last that you
created. At any time you can get the stash back.
Git-Stash
how to use it ? - stash p. 4
federico.panini@fazland.com - CTO
How to stash back your files ?
$ git stash apply --index
# On branch feature/610_i18N_de_ro
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: routing_de.yml
# modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php
# modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
#
# modified: scripts/crontab
#
When your critical bug fixing is done you can get the files back from the stash
and continue you development on that files
Git-Stash
BEST PRACTISES - stash message
federico.panini@fazland.com - CTO
If you don’t give a message comment to a stash git automatically creates it
taken it from the last commit log message. This could be a bit confusing when
your working with multiple stash and could lead to errors … huge errors!
So the adivice is to use git stash save “message”.
This command is equal to git stash with the difference that you can give a
message name to the stash
$ git stash save “stash fiels for #610 working progress on upload image bug fixing ”
# On branch feature/610_i18N_de_ro
# Changes to be committed:
Git-Stash
BEST PRACTISES - stash lifetime p.1
federico.panini@fazland.com - CTO
Git Stash is used for switching quickly between branches when you have to
work on multiple different tasks, or when suddenly you have to fix a critical bug.
Considering that the stash is “shared” between all the git repository it is not
absolutely advised to leave the code in the stash for a long period. The stash is
a quick “knife tool” which will help you with sudden “code” events.
Git-Stash
BEST PRACTISES - stash lifetime p.2
federico.panini@fazland.com - CTO
If you plan to work on a new feature for
a long time period, instead of putting
the working files your on in the stash
you can create a branch for them:
BRANCH IT!
$ git stash branch testchanges
Switched to a new branch "testchanges"
# On branch testchanges
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: routing_de.yml
# modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php
# modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
#
# modified: scripts/crontab
#
Dropped refs/stash@{0} (f0dfc4d5dc332d1cee34a634182e168c4efc3359)
Git-Stash
dropping a stash
federico.panini@fazland.com - CTO
When your stash has been got back you can delete it. Remember that it’s
always a best practice to delete your stash just after you got back from stash
stack.
$ git stash drop stash@{0}
Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)
Git-Stash
Command reference
federico.panini@fazland.com - CTO
• git stash list
• git stash
• git stash save message
• git stash apply —index
• git stash drop stash{n}
• git stash branch branchname
Git-Stash
Reference
federico.panini@fazland.com - CTO
• http://git-scm.com/book/en/v1/Git-Tools-Stashing
• https://www.kernel.org/pub/software/scm/git/docs/git-stash.html
• http://gitready.com/beginner/2009/01/10/stashing-your-changes.html

More Related Content

What's hot (20)

KEY
Git Basics at Rails Underground
Ariejan de Vroom
 
PDF
Git: basic to advanced
Yodalee
 
PDF
Juliette Reinders Folmer - Promote your open source project with GitHub Pages...
Codemotion
 
PPTX
Git and git workflow best practice
Majid Hosseini
 
PPTX
Git basics : a beginner's guide
Digital Product School
 
KEY
Git Magic: Versioning Files like a Boss
tmacwilliam
 
PPT
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 
PDF
Introduction to Git
Rick Umali
 
PDF
Using Git on the Command Line
Brian Richards
 
DOCX
Git github
Anurag Deb
 
PPTX
News from EGit - Talk EclipseCon Europe 2014 - Ludwigsburg
msohn
 
ODP
GIT from n00b
Supachai Vorrasing
 
PDF
Git Tricks
Ivelina Dimova
 
PDF
Bedjango talk about Git & GitHub
BeDjango
 
PDF
Git - Get Ready To Use It
Daniel Kummer
 
PPT
Github By Nyros Developer
Nyros Technologies
 
PDF
Getting Started with Git
Rick Umali
 
PDF
#5 - Git - Contribuindo com um repositório remoto
Rodrigo Branas
 
PPTX
Git operation 101
Kyohei Moriyama
 
PDF
Undoing Things in Git
gittower
 
Git Basics at Rails Underground
Ariejan de Vroom
 
Git: basic to advanced
Yodalee
 
Juliette Reinders Folmer - Promote your open source project with GitHub Pages...
Codemotion
 
Git and git workflow best practice
Majid Hosseini
 
Git basics : a beginner's guide
Digital Product School
 
Git Magic: Versioning Files like a Boss
tmacwilliam
 
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 
Introduction to Git
Rick Umali
 
Using Git on the Command Line
Brian Richards
 
Git github
Anurag Deb
 
News from EGit - Talk EclipseCon Europe 2014 - Ludwigsburg
msohn
 
GIT from n00b
Supachai Vorrasing
 
Git Tricks
Ivelina Dimova
 
Bedjango talk about Git & GitHub
BeDjango
 
Git - Get Ready To Use It
Daniel Kummer
 
Github By Nyros Developer
Nyros Technologies
 
Getting Started with Git
Rick Umali
 
#5 - Git - Contribuindo com um repositório remoto
Rodrigo Branas
 
Git operation 101
Kyohei Moriyama
 
Undoing Things in Git
gittower
 

Similar to Git in pills : git stash (20)

PPTX
Learn Git form Beginners to Master
C. M. Abdullah Khan
 
PDF
Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...
msohn
 
PDF
devops-complete-notes-2.pdf
RobinRohit2
 
PDF
Git basics a starter on git and its ecosystem
François D'Agostini
 
PPTX
Intro to git and git hub
Venkat Malladi
 
PDF
Git best practices workshop
Otto Kekäläinen
 
PDF
How to git easily in day to-day work
Alena Radkevich
 
PPTX
Introduction into Git
Serhii Kartashov
 
PPTX
Git and Github
Teodora Ahkozidou
 
PPTX
Mastering git - Workflow
Tahsin Abrar
 
PPTX
Git 101 - An introduction to Version Control using Git
John Tighe
 
PPTX
Source Control Using Git
Chris Mylonas
 
PPT
Learn Git Basics
Prakash Dantuluri
 
PDF
01 git interview questions &amp; answers
DeepQuest Software
 
PPTX
GIT In Detail
Haitham Raik
 
PPTX
Git
Parag Gupta
 
PDF
A Practical Introduction to git
Emanuele Olivetti
 
PPTX
Ultimate Git Workflow - Seoul 2015
Atlassian 대한민국
 
PDF
Git Interview Questions PDF By ScholarHat
Scholarhat
 
Learn Git form Beginners to Master
C. M. Abdullah Khan
 
Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...
msohn
 
devops-complete-notes-2.pdf
RobinRohit2
 
Git basics a starter on git and its ecosystem
François D'Agostini
 
Intro to git and git hub
Venkat Malladi
 
Git best practices workshop
Otto Kekäläinen
 
How to git easily in day to-day work
Alena Radkevich
 
Introduction into Git
Serhii Kartashov
 
Git and Github
Teodora Ahkozidou
 
Mastering git - Workflow
Tahsin Abrar
 
Git 101 - An introduction to Version Control using Git
John Tighe
 
Source Control Using Git
Chris Mylonas
 
Learn Git Basics
Prakash Dantuluri
 
01 git interview questions &amp; answers
DeepQuest Software
 
GIT In Detail
Haitham Raik
 
A Practical Introduction to git
Emanuele Olivetti
 
Ultimate Git Workflow - Seoul 2015
Atlassian 대한민국
 
Git Interview Questions PDF By ScholarHat
Scholarhat
 
Ad

More from Federico Panini (8)

PDF
Long life to vagrant… Vagrant is dead
Federico Panini
 
PDF
Machine Learning: strategie di collaborative filtering nelle piattaforme onli...
Federico Panini
 
PDF
Vagrant boxes with x, export display, chrome headless
Federico Panini
 
PDF
Aws vpc : addressing cidr
Federico Panini
 
PPTX
Symfony & Mailcatcher
Federico Panini
 
PDF
Elasticsearch quick Intro (English)
Federico Panini
 
PDF
Elasticsearch a quick introduction
Federico Panini
 
PDF
Elk - Elasticsearch Logstash Kibana stack explained
Federico Panini
 
Long life to vagrant… Vagrant is dead
Federico Panini
 
Machine Learning: strategie di collaborative filtering nelle piattaforme onli...
Federico Panini
 
Vagrant boxes with x, export display, chrome headless
Federico Panini
 
Aws vpc : addressing cidr
Federico Panini
 
Symfony & Mailcatcher
Federico Panini
 
Elasticsearch quick Intro (English)
Federico Panini
 
Elasticsearch a quick introduction
Federico Panini
 
Elk - Elasticsearch Logstash Kibana stack explained
Federico Panini
 
Ad

Recently uploaded (20)

PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 

Git in pills : git stash

  • 3. Git-Stash save your work during work :) [email protected] - CTO The problem When your working on a ticket to solve a bug or to implement a new feature, frequently happens that you need to switch to another branch for solving a problem that has occurred. So what to do ? Your actual work is in a messy state you have new files, uncommitted ones …
  • 4. Git-Stash save your work during work :) [email protected] - CTO You could commit your amends and switch to the other branch for solve a bug: DON’T DO IT! You’ll loose all of the informations about your progress and also you’re storing a commit with inconsistent code.
  • 5. Git-Stash save your work during work :) [email protected] - CTO How can I leave the state of my current branch clean, and switching to another branch ? use GIT STASH Using git stash will allow you to maintain the dirty state of your current working directory and saves it on a stack of unfinished changes that you can reapply at any time.
  • 6. Git-Stash how to use it ? - stash p. 1 [email protected] - CTO Stashing your current files is easy and simple: in your directory where messy files are type: $ git status # On branch feature/610_i18N_de_ro # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: routing_de.yml # modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php # modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # # modified: scripts/crontab # You’ll see a list of unstaged files.
  • 7. Git-Stash how to use it ? - stash p. 2 [email protected] - CTO Stashing your current files is easy and simple: in your directory where messy files are now type: $ git stash Saved working directory and index state "WIP on feature/610_i18N_de_ro: 049d078 added the index file" HEAD is now at 049d078 added the index file (To restore them type "git stash apply") Now your working directory is clear $ git status # On branch feature/610_i18N_de_ro nothing to commit, working directory clean at this point you can freely switch to another branch do whatever you need to do to fix bugs or implement new feature
  • 8. Git-Stash how to use it ? - stash p. 3 [email protected] - CTO Where are your stashed files now ? $ git stash list stash@{0}: WIP on feature/610_i18N_de_ro: 049d078 added the index file stash@{1}: WIP on feature/610_i18N_de_ro: c264051 Revert "added file_size" stash@{2}: WIP on feature/610_i18N_de_ro: 21d80a5 added number to log You can see a list of stashes and the first one (stash{0}) is the last that you created. At any time you can get the stash back.
  • 9. Git-Stash how to use it ? - stash p. 4 [email protected] - CTO How to stash back your files ? $ git stash apply --index # On branch feature/610_i18N_de_ro # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: routing_de.yml # modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php # modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # # modified: scripts/crontab # When your critical bug fixing is done you can get the files back from the stash and continue you development on that files
  • 10. Git-Stash BEST PRACTISES - stash message [email protected] - CTO If you don’t give a message comment to a stash git automatically creates it taken it from the last commit log message. This could be a bit confusing when your working with multiple stash and could lead to errors … huge errors! So the adivice is to use git stash save “message”. This command is equal to git stash with the difference that you can give a message name to the stash $ git stash save “stash fiels for #610 working progress on upload image bug fixing ” # On branch feature/610_i18N_de_ro # Changes to be committed:
  • 11. Git-Stash BEST PRACTISES - stash lifetime p.1 [email protected] - CTO Git Stash is used for switching quickly between branches when you have to work on multiple different tasks, or when suddenly you have to fix a critical bug. Considering that the stash is “shared” between all the git repository it is not absolutely advised to leave the code in the stash for a long period. The stash is a quick “knife tool” which will help you with sudden “code” events.
  • 12. Git-Stash BEST PRACTISES - stash lifetime p.2 [email protected] - CTO If you plan to work on a new feature for a long time period, instead of putting the working files your on in the stash you can create a branch for them: BRANCH IT! $ git stash branch testchanges Switched to a new branch "testchanges" # On branch testchanges # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: routing_de.yml # modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php # modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # # modified: scripts/crontab # Dropped refs/stash@{0} (f0dfc4d5dc332d1cee34a634182e168c4efc3359)
  • 13. Git-Stash dropping a stash [email protected] - CTO When your stash has been got back you can delete it. Remember that it’s always a best practice to delete your stash just after you got back from stash stack. $ git stash drop stash@{0} Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)
  • 14. Git-Stash Command reference [email protected] - CTO • git stash list • git stash • git stash save message • git stash apply —index • git stash drop stash{n} • git stash branch branchname
  • 15. Git-Stash Reference [email protected] - CTO • http://git-scm.com/book/en/v1/Git-Tools-Stashing • https://www.kernel.org/pub/software/scm/git/docs/git-stash.html • http://gitready.com/beginner/2009/01/10/stashing-your-changes.html