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:
- $ git add .
- $ git commit -m "Temporary commit"
- $ git checkout -b my_branch
- $ git pull ssh://user@remote.host:port/path/to/repository my_branch
- $ git reset 'HEAD^'
A final git reset 'HEAD^'
on the remote makes the commit to have never happened.