4

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?

  1. I don't work at home
  2. Use portable drive
  3. Do exact what the OP said
  4. Other
Jeon
  • 3,597
  • 3
  • 24
  • 67
  • 1
    well sometimes I have to do same thing. If you don't want to see those commits in your history you can just revert them. If there is efficient&better way I would like to know. – FatmaT Feb 25 '16 at 15:58
  • I such a case I work on another branch and commit everything, push to server for remote access and backup. When it's done, I rebase -i everything in 1 or more meaningfull commits, rebase my branch on master so I will be fast forward and merge into my master (which is totally linear). – LFI Feb 25 '16 at 16:06

2 Answers2

2

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.

Community
  • 1
  • 1
Peter
  • 2,422
  • 2
  • 14
  • 18
  • I agree with @Peter. Branch off of whatever you're doing with 'git checkout -b TravelBranch', finish the task after arriving at you're destination, then merge the temporary branch back into the original branch. This should be a simple fix, without interfering with anyone else working on the original branch. – DeveloperDemetri Feb 25 '16 at 16:55
0

There is a couple of options:

  • use a public remote-branch
  • use another repository (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:

  • set up a new repository for your private work
  • add the new repository as a remote
  • add a new sync branch locally
  • add a tracking branch from the sync branch to the new repo
  • when you want to sync your environments make your local branch look like you want it to
  • force push the local branch
  • on the remote machine do a fetch. and reset the sync branch to remote/sync

See:

Community
  • 1
  • 1
Alexander Oh
  • 20,413
  • 12
  • 65
  • 70