Git: Pull immature work without dirty commit

Yesterday I wanted to continue ongoing work I started on a different machine. But the code was not clean when I left, so I didn’t commit.

To prevent a dirty commit I temporarily committed my work on the remote machine, then pulled that commit directly from there and afterwards discarded the temporary commit on the other machine. No bad commit left:

  1. $ git add .
  2. $ git commit -m "Temporary commit"
  1. $ git checkout -b my_branch
  2. $ git pull ssh:// my_branch
  3. $ git reset 'HEAD^'

A final git reset 'HEAD^' on the remote makes the commit to have never happened.


Leave a comment

Your comment