Stash: git stash

Git Tips & Commands

Learn the intricacies of Git commands and explore career advancement through coding classes. This guide offers helpful syntax for stashing, listing, restoring, and removing stashes in Git, as well as information about relevant courses in web development, Python, data science, and web design.

Key Insights

  • To stash uncommitted code for later use in Git, utilize the commands 'git stash' or 'git stash save "A meaningful name/message". Multiple stashes can be created and named for easy identification.
  • 'git stash list' command is used to see a list of your stashes.
  • Restoration of the latest stash can be accomplished with the 'git stash pop' command. This command can also be used to apply a specific stash and remove it from the stash list or apply a specific stash and keep it in the stash list.
  • Deletion of all stashes is done using the 'git stash clear' command. A specific stash can be removed by using the 'git stash drop stash@{0}' command.
  • Furthering one's education in coding can open up new career opportunities. Courses offered include web development, Python, data science, and web design.
  • Small, hands-on, and expert-led classes are available at the NYC web development school, NYC Python bootcamp, NYC data science school, and NYC web design school.

Git Hygiene Checklist

  • Use the imperative mood: 'Add login form' not 'Added login form'.

  • Avoid divergent histories that need merging.

  • Never commit build artifacts, secrets, or local config.

  • One branch = one PR = one focused change.

For All the Commands Below

The commands below assume you've navigated to the folder for the Git repo.

Create a Stash

To stash away your uncommitted code for later, run one of these commands:

  • Git stash
  • Git stash save "A meaningful name/message"
  • NOTE: You can have multiple stashes. You're not required to name each stash, but you may want to give it a meaningful name.

List Stashes

To see a list of your stashes, run this command:

Full-Stack Web Development Certificate: Live & Hands-on, In NYC or Online, 0% Financing, 1-on-1 Mentoring, Free Retake, Job Prep. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.
  • Git stash list

Restore/Apply a Stash

To apply the latest stash, run this command:

  • Git stash pop
    • To apply a specific stash (and remove it from the stash list), run the following command. (Replace stash@{0} with the stash you want to restore, which you find in the list of stashes):
  • Git stash pop stash@{0}
    • To apply a specific stash (and keep it in the stash list), run the following command. (Replace stash@{0} with the stash you want to restore, which you find in the list of stashes):
  • Git stash apply stash@{0}

Removing Stashes

To deletes all stashes, run this command:

  • Git stash clear

To delete a specific stash, run the following command. (Replace stash@{0} with the stash you want to delete, which you find in the list of stashes):

  • Git stash drop stash@{0}

Go Beyond Git

We offer a full suite of coding courses. Classes are small, hands-on, and expert-led. Check out our coding bootcamps and schools now:

Topics

Learn more in these courses

How to Learn Git

Master Git with hands-on training. Git is a free, open-source version control system that allows developers to track the changes they make to code.

Yelp Facebook LinkedIn YouTube Twitter Instagram