Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for git stash
Stefan Alfbo
Stefan Alfbo

Posted on

     

git stash

Thegit stash is probably one of my most used git commands afterpull andpush.

This command can be useful when you need to switch branches, but the current changes are not ready to be committed. Or you're experimenting with the code but unsure if it's worth committing to the history of the repository. The stashing allows you to temporarily set aside the current work which can also be good if you want to sync the local branch with the remote repository.

The simplest workflow withgit stash is just to usegit stash which will save your local modifications away and reverts the working directory to match the HEAD commit.

git stash

Then later on when you want to come back to your modification, usegit stash pop.

git stash pop

However there are more power to this command than the example above. Here are some other sub-commands to thegit stash command.

# List the stash entries that you currently have.git stash list# Creates and checks out a new branch named <branchname># with the stashed codegit stash branch <branchname># Stash with a messagegit stash push-m"<descriptive message>"# Stash untracked filesgit stash-u# Apply a specific, n, stash from the stash listgit stash apply stash@{n}
Enter fullscreen modeExit fullscreen mode

I like to use the commandgit stash push -m"my message" when stashing, that will make it far easier to know what each stash is containing.

stash with message

Will look like this when using thegit stash list command.

git stash list

Happy stashing!

Top comments(6)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
natescode profile image
Nathan Hedglin
Lead Software Engineer with a decade of experience. I'm currently leading a team doing insurance software development.
  • Location
    USA
  • Education
    Ridgewater College
  • Pronouns
    awe/some
  • Work
    Lead Software Engineer @ProAg
  • Joined

git stash --all is generally what a dev wants. Stash everything that is or isn't tracked. I have my aliased togit sta

CollapseExpand
 
stefanalfbo profile image
Stefan Alfbo
Software developer that is passionate about learning new technologies and solving complex problems. Always trying to be curious and open minded to improve my skills.
  • Location
    Sweden
  • Education
    KTH Royal Institute of Technology
  • Work
    Software developer
  • Joined

Indeed, that is a great flag to use and a great recommendation, thanks!

CollapseExpand
 
bobbyiliev profile image
Bobby Iliev
I am a professional DevOps Engineer with a demonstrated history of working in the internet industry. I am an avid Linux lover and supporter of the open-source movement philosophy.
  • Location
    Sofia, Bulgaria
  • Work
    DevEx @ Materialize | Community Manager @ DigitalOcean | Co-Founder @ DevDojo | Docker Captain
  • Joined

Great post! 👏

CollapseExpand
 
chandrashekhar profile image
Chandrashekhar Mehta
Artist | Developer | Engineer
  • Location
    India
  • Education
    Saffrony Institute of Technology
  • Pronouns
    he/him
  • Work
    Engineering Student
  • Joined
• Edited on• Edited

didn't knew about this, will use it from now, thank you !!

CollapseExpand
 
ccoveille profile image
Christophe Colombier
Smiling person, father of two, Husband, Senior Developer/Architect (in that exact order, it's important)Experience in development since 2004Linux user and advocate since 2001
  • Location
    Villeurbanne, France
  • Education
    Arts et Métiers
  • Work
    VP Technology
  • Joined

git stash is a dear old friend, I'm happy to see some people loves it and are promoting its use

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software developer that is passionate about learning new technologies and solving complex problems. Always trying to be curious and open minded to improve my skills.
  • Location
    Sweden
  • Education
    KTH Royal Institute of Technology
  • Work
    Software developer
  • Joined

More fromStefan Alfbo

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp