Git has a number of good features designed to improve user experience with Github and reduce the chances of data loss. Earlier I have explained about Solution: Github ‘Please tell me who you are’ error. Today I am going to explain about the common message which you might get when executing pull command.
Recently I was trying to run git pull –rebase command but I got message like
1 2 3 4 5 | $ git pull --rebase Cannot pull with rebase: You have unstaged changes. Please commit or stash them. |
Git stash command is kind of commit stored changes to temporary space and clean working copy. Then your working copy will be reverted to HEAD.It is a good place to store uncommitted changes.
When you stash the changes, your changes will be stored in temporary space and your working copy will be reverted to HEAD
git pull –rebase is a good practice to use in general.This is very specific problem when you pull data from server so let’s check it with example
You have changes that have not been committed and you are going to pull changes from the server, you will get above error.This error says commit your local changes before you pull or stash changes mean store local changes to another place for temporary and get back with pop.
You can do this to work around using following steps
1. stash your changes with: git stash
2. pull from master with rebase: git pull –rebase
3. Then execute simpler git stash pop. With this command, it deletes that stash for good, while apply does not.
Here I have used git stash pop but After changes have been stashed, there are a few options of to get changes back to local:
1. git stash pop: This command takes a stashed change and removes changes from the stash stack and apply it to your current working tree.
2. git stash applies
3. git stash branch: This command creates a new branch from the same commit you were on when you stashed the changes and applies the stashed changes to the new branch.
Experiment with the stash before using it on some really important work 🙂
Comments (1)