I always use git rebase to sync my code, I found that git stash
saves the current work and after fetching the latest code from master we can merge it with our code by using git stash pop
.
Suppose the sequence is:
git stash
, i.e. my current work is savedgit checkout master
, then git pull master
, i.e. I have fetched latest code from mastergit checkout mybranch
git stash pop
I guess this will merge my work with updated code, if instead of git stash pop
I will dogit rebase master
then the result will be the same or not?
Your suggestion and help will be appreciated, Thanks for your time.
Since they're not on a branch, rebase does not touch them, and in your workflow, it's the git stash pop that brings the work-tree changes into your new work-tree. However, if you make your own (normal) commit, on a branch, and rebase and include that commit, this normal commit will be rebased along with any others.
git stash pop. Throws away the stash after applying it, whereas git stash apply leaves it in the stash list for possible later reuse. This happens unless there are conflicts after git stash pop, in which case it will not remove the stash, leaving it to behave exactly as git stash apply.
What is git rebase? Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow.
The stash is meant to store changes that are not meant to be commited yet. For example if you are working on something that isn't done yet, and you want to work on something else for a while without committing the unfinished work, then you use a stash to store it for later use.
If you however have actual commits, that contain finished work, then use either git merge
or git rebase
to merge/rebase those commits into the history.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With