tags:

views:

310

answers:

2

Git newbie here. Is there a way to synchronize two repositories, so that the current checked out files will be the latest version of all the changes?

What I have is this:

Desktop       Server
-------       ------
Change_X      Change_Y

And I would like to enter some "magic" command, and then the changes are merged

Desktop       Server
-------       ------
Change_X      Change_X
Change_Y      Change_Y

One of the problems is that the desktop is a Windows machine behind a NAT, and I would like to avoid having to set up sshd on it. Basically I would like to do it all using ssh from the desktop to the server.

This seems like it should be trivial to do with git, but I couldn't figure out how to do it.

(I thought git push would do the trick, but it turns out it doesn't make changes to currently checked-out branches, so the changes from the desktop don't get to the server)

Is there a way to do this with git, or am I off the track?

Solution: I downloaded the post-update script from here and put it in the hooks directory on the server, and now git push causes the server to update with the changes. So basically the "magic command" resolves to:

git pull server:scripts/ master
git push server:scripts/

(scripts is the folder I'm synchronizing)

+2  A: 

it should be possible to create a post-commit hook that will update server's working copy on change (I did exactly the same with mercurial, so i assume it would be possible with git too). so after you push, working copy will be updated automatically.

create post-commit hook that will run git up or whatever equivalent command for git is.
i'm sorry i don't know what else to say.
upd: there is some explanation in official git faq.

SilentGhost
+1  A: 

One of the problems is that the desktop is a Windows machine behind a NAT, and I would like to avoid having to set up sshd on it. Basically I would like to do it all using ssh from the desktop to the server.

Not a direct answer to your question, but if you're behind a NAT, the easier thing to do is to run a reverse SSH tunnel using Putty or something, instead of an sshd server.

ssh -R3333:127.0.0.1:9418 <user>@<server>

Now, connections to <server>'s port 3333 will be forwarded to your NAT-ed machine's git port.

codelogic