Git keep staged changes

How do I keep my staged changes without committing and work on other issue’s where these changes are not required ?

I have created a branch say b1 and made some changes and staged that changes. Now I had an urgent issue which I need to work on but I don’t require the staged changes here. So I switched to branch b2 and fetched and pulled from upstream. But the staged changes still exists in the b2 branch

  • When to use a bare Git repository?
  • Git on Yosemite keeps asking for remote username and password
  • How to propagate GIT Hook while clone
  • How to organize GAE Modules app structure and code?
  • How to do git pull request from intellij idea?
  • How to automatically use git diff --word-diff option for *.tex files but not others?
  • Git workflow: forking a project and maintaing a local modified copy, but keep up to date
  • How to stop Google indexing my Github repository
  • Trac 1.0 unable to browse source for Git repository
  • Output every file status in a git tree
  • Where does git store information about the origin of a repository
  • How To Launch Git Bash from DOS Command Line?
  • 3 Solutions collect form web for “Git keep staged changes”

    Do not stage, but stash the changes. You can then later apply them again to your working copy:

    git stash
    git checkout -b urgent-issue
    git commit
    git checkout -
    git stash pop

    An alternative to the answer given by @knittl is to actually go ahead and make a temporary commit (keep reading):

    git commit -m 'WIP'
    git checkout urgent-issue

    Once you have committed your work, your working directory will be clean and you can switch branches as you need. When you want to return to your current branch, you can continue the work and amend the temporary commit you made.

    git checkout feature   # return to original branch
    # work work ... complete the commit
    git commit --amend -m 'Finished the work I started earlier'

    I usually prefer making a temporary commit over a stash when I have critical work for several reasons. First, it eliminates the need to have to sort through the stash stack looking for the stash I want to apply (and it easy to let the stack pile up with old junk). Second, because I know that I have a commit with unfinished work, it forces discipline on me to complete the feature.

    # No need to stage
    # put your current changes in stash
    git stash
    # create and checkout to b1 branch
    git checkout -b b2
    # resolve urgent issue and push changes 
    # now get back to branch b1
    git checkout b1
    # Apply stashed changes back
    git stash pop
    Git Baby is a git and github fan, let's start git clone.