Skip to content
Advertisement

Connect local git repos on windows and raspberry pi

I have a windows machine and a raspberry pi, each with a git repo. I was able to set it up so I can pull from the pi to windows with the following command:

git remote add pi@192.168.3.101:/home/pi/code/

This should be stable since the pi is set to a static local IP. I’d like help with an equivalent command to run on the pi so I can pull from the windows machine to the pi given that the windows machine is not set to a static ip (maybe using the machine name?). I’m still learning the ropes when it comes to windows/linux interaction and nothing I googled seemed to turn up what I was looking for.

I don’t want to put the code up on github, so please don’t suggest that. And I want to be able to develop on either machine so that means neither repo can be setup as bare. I appreciate any help!

Advertisement

Answer

You could install an ssh server on the Windows machine, or a Git repository service. But it’s not a normal use of Git to have repositories pushing to each other. Don’t do it. The normal use is to designate one central location that all remote repositories push to and pull from. That central location could be your raspberry pi.

However, the repository to push to should be a so-called bare repository. I’m guessing that the location /home/pi/code is a working tree, not a bare repository. I suggest to create a bare repository on the raspberry pi, to be used by both the workspace on raspberry pi, and the workspace in windows. Here’s one way to do it.

Create a bare repository in /home/pi/repos/code.git (or wherever you like) by cloning from /home/pi/code:

git clone --bare /home/pi/code /home/pi/repos/code.git

Add this bare repository as the remote in both the working tree on raspberry by and on windows using the git remote command.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement