Search code examples
gitworkflowsquash

How can I safely use git rebase when working on multiple computers?


I work on the same project on two different computers, desktop and laptop. Sometimes I need to transition between them while in the middle of some task/feature.

So I want to make a commit on the laptop, and then transport (push/pull) it to the desktop and continue. Then, when the feature is complete I want to make a new commit and then squash it with the half-done commit.

How can I now pull/push it back to the laptop without confusing the history?

What's the proper way of handling this? After doing this, I must also be able to publish the commits. Currently I'm working on the master branch directly, but if working on a separate branch helps I will do that.

I do know how to use git rebase -i, and have used it a few times while still on the same computer without a problem, so your answer does not have to include the details of git rebase/squash.


Solution

  • I do this all the time and use the following workflow, using github as an authorative master repository when I'm not sitting at any given computer:

    When I leave a computer i always do

     git push -f
    

    When I arrive at a computer I do

    git fetch -v
    git reset --hard origin/master # Assuming branchname is master
    

    As long as I always do the same, I know my latest work is always on github, and I rebase all I want

    I generally also set

    git config --global push.default current
    

    to push only the branch I have checked out, something I find to be almost mandatory when using a lot of forced push.