0

I settled on using VCS for synchronization between my laptop and main computer. At that time, I liked bzr very much, so I used it. The workflow was simple - on main machine I had a script, which detected the appearance of laptop nearby and executed following steps:

  • bzr pull
  • bzr update
  • bzr push
  • ssh to laptop, update the repo there

Now, I slowly moving towards git - not the last reason for that is Github and git's superior speed. But I failed to set up the same workflow with git. First, it refused to push into checked-out repository - I solved that with receive.denyCurrentBranch = "warn", and doing git reset --hard. But this way, I lose any changes that I made on my laptop, if they were not commited. I tried using "git reset --merge", but (unlike bzr) it refused to merge some of the conflicting files.

Is there a way to solve these problems with git?

Rogach
  • 26,050
  • 21
  • 93
  • 172

1 Answers1

1

It's totally doable with git, but it seems to me like either you're not describing your environment completely (why push? where is the "origin"?), or you're confusing terms between bzr and git.

On the "main computer" (it's a good idea that the main repo not be changed and be a "bare" repo, or have a third origin repo):

git commit -am "Auto committing"

no need for pushing here.

then ssh to laptop:

git pull <main_computer's remote> master

This is provided you are both currently on the same branch, namely master, of course. There are more sophisticated ways to do it more safely, but for the simplest case of 2 machines and no third origin, this should do. Finally, you can set the merge strategy for collisions, see git help merge

Not_a_Golfer
  • 47,012
  • 14
  • 126
  • 92
  • If I have some uncommited changes in the repo I pull to (rep1, for example), git says "Your local changes to ... would be overwritten". How do I work around this? – Rogach Mar 27 '12 at 14:06
  • you can also `stash` your changes, then pull, then try to merge the stashed changes. see `git help stash` – Not_a_Golfer Mar 27 '12 at 14:18