
you start to realize truly how powerful of a tool git is. In conjunction with other commands such as git pull, git merge, etc. Two of the most useful commands I have found are ‘git rebase’ and ‘git stash’.
#Git stash commands how to#
When I moved onto larger apps and began working at a company with a dozen engineers I began learning how to use branches, and how to use pull requests to merge my changes to the code base without affecting the other engineers code. Every once in a while I would have a project I would be working on with one other engineer, but a lot of the progress was made during pair programming sessions, where we would just push all the changes directly to master. The git stash command provides parameters for caching both types of files.stash untracked files can be used with -u or -include-untracked.Use the -a or -all commands to stash all changes in the current directory.When I was first learning to code, I would be the only engineer working on an app. New files in the working directory (untracked files) Git tracked changes that were not added to the staging area Modifications added to staging area (staged changes) Stay untracked or ignored filesīy default, git stash caches the following files: This command creates a new branch with the modifications in stash and deletes the stash when it is created successfully 7. +++ -1 +1,2 Create branches from stash $ git stash branch testchanges

Add -p or-patch after this command to see all diff for a particular stash, as follows: You can use the git stash show command followed by the stash name.Examples are as follows: $ git stash show Remove stash $ git stash WIP on master: 049d078 added the index WIP on master: c264051 Revert "added WIP on master: 21d80a5 added number to log View existing stash $ git stash WIP on master: 049d078 added the index WIP on master: c264051 Revert "added WIP on master: 21d80a5 added number to logĤ. You can use a name to specify which stash to use, and by default, the closest stash (that is, 3. You can use the git stash apply command to apply stash from the cache stack to the working directory multiple times without deleting the stash copy $ git stash apply Delete the first stash in the cache stack and apply the corresponding modifications to the current working directory $ git stash popĢ. $ git stash On autoswitch: test-cmd-stashĢ. HEAD Now at 296 e8d4 remove unnecessary postion reset in onResume function Saved working directory and index state On autoswitch: test-cmd-stash In practice, it is recommended to add a message to each stash to record versions $ git stash save "test-cmd-stash"

Saved working directory and index state WIP on master: 5002d47 our new homepage It is important to note that stash is local and will not be uploaded to git server via the git push command.

