Essential Git for Scientists
  • Introduction
  • Basic Concepts
    • Version Control
    • Git
    • Repo
    • Commits
    • Branches
    • Remotes
    • GitHub
    • De-centralisation
    • Summary
  • Basic Operations
    • Install Git
    • Create a Repo
    • Make a Commit
    • Inspect a Previous Commit
    • Revert a Change
    • Make a Branch
    • Extend a Branch
    • Fast-forward merge
    • Resolve conflicts
  • Intermediate Concepts
    • Commits
    • Three Trees
    • Rebase
    • Fetch
    • Pull
    • Push
  • Advanced Concepts
    • Reset
    • Interactive rebase
    • Formatted patches
    • Blame
    • Stash
    • Log filter
  • Cookbook
    • Undo
    • Branches
    • Diff
    • Stash
    • Merge
    • Hooks
    • Squashing
    • Rebase
    • Interactive Rebase
    • LFS
    • Submodules
    • Remote
    • Force push
    • Identify merged branches
    • Formated patches
    • Apply patches
    • Interactive rebase
    • Squash commits
    • Pull rebase
    • Log
    • Blame
    • Biset
    • Reset
  • Exercise
    • Exercise 1
    • Exercise 2
Powered by GitBook
On this page
  • How to do
  • Commands
  1. Advanced Concepts

Stash

If you make some changes in file-1but want to switch to a different branch to do something else. If that branch also contains file-1 then your changes will be overridden. You have to temporarily save the changes and later apply them.

This is what git stash does. It saves all your edits yet to be commited in a stack. Once the changes are stashed, the repo is in a clean state prior to these edits.

How to do

The typical workflow

  • You stash the changes. You can also give it a name for later references. Otherwise it will be the last in first out (LIFO) order.

  • You can freely switch branches and do some other work.

  • You come back to the original branch and pop the change from the stash stack.

Commands

  • Save the changes: git stash

  • Show stashes and their indeces: git stash list

  • Apply the changes:

    • git stash apply will apply the last (the last save, as per LIFO), or

    • git stash apply stash@{n} choose the n-th stash to apply

PreviousBlameNextLog filter

Last updated 1 year ago