I often work on my desktop and end up with changes not worthy of a commit. I want to then switch to my laptop and continue work where I left off on my desktop (including all uncommitted changes). How do I best do this with git?
I almost, like, wanna do a temporary commit, pull that, then undo the commit both locally and remotely as if it never ever happened. Is this the approach or is it something else? And how do I do this?
>Solution :
Yes, what you’ve described is exactly what you’d need to do.
The notion of Git doing anything with "uncommitted changes" makes no sense at all, because commits are the only thing Git traffics in. Therefore you must commit in order to do the transfer.
So just make a commit, give it a useful message like wip, and push. Once you’ve pulled onto the other machine, if you don’t want to preserve that commit, you can "undo" it as a commit by saying
git reset @~1
…but be advised that if you do that, then later on you will need to force push in order to carry on.
Perhaps a better approach, because it avoids the force push, is to make a temporary branch:
git switch -c wip
git add .
git commit -m wip
git push
# and on the other machine
git fetch origin
git switch wip
git reset main # or wherever you were working when you created wip
git switch main # or wherever you were working
git branch -D wip