

Whilst you could easily create a new checkout of your project with the specific branch, it's faster to switch branches in Git natively, and saves setting up other tools like an IDE or a test server.

Sometimes, when you are working on a problem you need to drop it suddenly in order to work on a different problem, like a critical bug that has been reported against a production version of your code. You can subscribe to the feed if you want to receive new instalments automatically. Stashing just the index (staged changes) in Git is more difficult than it should be.This week's Git Tip of the Week is about keeping work in progress safe, known as stashing. This answer is therefore obsolete for Git 2.35+.
#Git stash files update
UPDATE January 2022: Git 2.35 has been released, and stash now supports a -staged parameter. $ git stash pop # to finish work on the saved changes $ git switch fixup-branch # switch to another branch $ git commit -m 'Massive' # commit fully tested changes $ git stash push -staged # save these changes to the stash $ git add -patch foo # add unrelated changes to the index Only the commit ends-up being in the stash and not on the current branch. This is similar to committing the staged changes, Unrelated issue that you don't want to forget to fix, you can do theĬhange(s), stage them, and use git stash push -staged to stash them When you are in the middle of massive changes and you find some Git stash now includes in its man page: Saving unrelated changes for future use The -patch option has priority over this one. This is similar toīasic git commit except the state is committed to the stash instead Stash only the changes that are currently staged. This option is only valid for push and save commands. Git stash now includes in its man page: -S -staged Unlike ' stash push -patch', -staged supports use of any tool to select the changes to stash-out, including, but not limited to ' git add -interactive' ( man). This mode allows to easily stash-out for later reuse some changes unrelated to the current work in progress.

(Merged by Junio C Hamano - gitster - in commit 44ac8fd, ) stash: implement '-staged' option for 'push' and 'save' See commit a8a6e06 (), and commit 41a28eb () by Sergey Organov ( sorganov). So this is now officially supported (8 years later). With Git 2.35 (Q1 2022), " git stash" ( man) learned the -staged option to stash away what has been added to the index (and nothing else). Then you can add another alias and run git move-staged: git config -global alias.move-staged '!bash -c "git stash-staged git commit -m "temp" git stash git reset -hard HEAD^ git stash pop"' If you do not want to keep staged files and want move them into stash. Git stash save -patch # for older git versionsĪnd git will ask you for each change in your files to add or not into stash.Īlias for DOUBLE STASH: git config -global alias.stash-staged '!bash -c "git stash -keep-index git stash push -m "staged" -keep-index git stash pop you can stage your files and then run git stash-staged.Īs result your staged files will be saved into stash. With latest git you may use -patch option git stash push -patch # since 2.14.6 This is similar to basic git commit except the state is committed to the stash instead of current branch.
#Git stash files how to
Here you can find how to stash only unstaged changes. Create the alias for this command: git config -global alias.stashs 'stash push -S'.
