Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use git to transfer uncommitted changes from one machine to another?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading