Reputation: 2091
I'm using sourcetree and only have master branch cloned locally. So I have been doing all my changes on master branch, and finally I have a lot of uncommited changes here on my local machine.
But right now I decided not to push them to master branch, but rather to develop branch - pretty old branch in my project. It exists on the origin, but not locally.
How can I first merge master to develop, so that they're the same, and then commit and push my changes to develop branch, leaving master untouched?
I've been thinking about:
git checkout origin/develop;
git merge master;
Ok, that would solve the first problem I think, but then my local changes would not be seen - source tree treats them as master changes I believe.
I am asking for this because I don't want to mess up anything in this project.
So - any suggestions?
Upvotes: 0
Views: 40
Reputation: 13294
Before git checkout
and git merge
, run
git stash
to save your uncommitted changes to the Git stash and remove them from your working tree. Then, after you've merged, run
git stash apply
git stash drop
to apply those changes you've stashed to your working tree (now on the develop
branch) and remove the changes from the stash. You could instead run git stash pop
, which combines apply
and drop
, but that has some tricky behavior (when hitting conflicts and such) that makes it better to usually just run apply
and drop
separately.
Upvotes: 1