git commit and push when work is not finished and I am moving workplace
I know that it is not a good idea to commit and push to a repository unfinished work.
Sometimes, however, I need to move workplace from company to home, and home to company. Having a temporary repository might solve the problem, but I think it needs some tiresome workaround:
$ cp ~/real_proejct ~/temp_project
$ cd ~/temp_project
$ git add . && git commit -m 'I am returning home' && git push temp_repo master
# Now I am home
$ cd ~/temp_project && git pull
# some edit
$ git add . && git commit -m 'I am going to company' && git push temp_repo origin
# In company
$ git pull
$ cp ~/temp_project ~/real_project
I think it's not a nice looking thing. In such case how do you deal with such situation?
Use a branch. See Git experimental branch or separate experimental repository? for syntax/example. (But I'm not sure cherry-pick is always the best though as suggested there... you can pull and merge full branches too.)
If other people are working on their own branches or on the master branch, you won't bother them with your code whether it compiles or crashes or what. Some people also use this for developing multiple independent features simultaneously. Maybe you are blocked by a bug, so you branch your code and then fix the bug, and then come back to your branch. It wouldn't make sense to commit nonworking code before it can work right.
There is a couple of options:
git remote
is your friend) be aware, that if you push unfinished work it might be interesting to force pushes to get rid of broken history (rebase/refactor your commit history before pushing).
I would recommend to do the following:
See:
上一篇: 带注释和不带注释的标签有什么区别?