I've been developing across 2 devices.
What I would usually do, when needing to head out and use my laptop, is mass stage my pending changes, commit them, and push them so I can resume development by pulling from my laptop later on.
However, obviously it's a bad practice to just stage a bunch of random changes and push them under a blanket commit.
Is there some way to push a git stash, pull the stash, and have all the stages pending still, on the other device.
Doing a commit on a temporary branch that you then push isn't breaking any Git idioms. You can clean up commit messages and the like later.
If you're set against using an actual commit, you can stash and then save the stash in patch format.
git stash #stash everything
git stash show -p > stash.diff #save patch-formatted stash to file
Then you just need to get the stash.diff
file onto the second machine and do git apply stash.diff
.
If you're alone on the branch and don't have to share its history with coworkers, what I'd suggest is to use a temporary commit :
From Machine 1, on your branch :
# you have unfinished modifications to "save"
git commit -am "temp"
git push origin HEAD
From Machine 2, on your branch :
# get your last commit like you usually do, let's say
git pull
# now let's "uncommit" the ugly temp
git reset HEAD^
(as a reminder, git reset
without --soft
or --hard
makes it a default --mixed
mode. It makes that modifications are kept in the working tree, so it's only the branch pointer which is set to a different commit)
At this point you have the pending modifications from Machine 1, ready to be furtherly modified, added and "properly" commited when you're ready.
Lastly, as you asked in comment, yes, you'll have to force push either way when you want to reflect back on the remote (which still has the temp commit you locally destroyed, to be replaced with yours).
And of course thanks to torek for the useful optimization.
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