Home > Net >  Sync a git repository between two local devices without internet connection
Sync a git repository between two local devices without internet connection

Time:05-23

I have a repository repo on github and I have its clone on my local system (mac) which I use to make edits and push on daily basis; mac has an internet connection for doing this.

But the project is deployed on a NVIDIA Jetson device jetson which does not have access to an internet connection at all times. (This is because I have disabled dhcp to provide a static IP to its eth0 interface.) For deployment and testing, I use various ssh tools to migrate the code from mac to jetson.

How can I sync the repository on mac and jetson which only communicate via ssh ?

CodePudding user response:

If you don't need the full history of the repository on the destination side, you might consider git archive instead of git bundle.

That way, you have only one file (an archive) to rsync or scp over, and then uncompress.

CodePudding user response:

If you have git available on jetson and if git push jetson master looks like a desirable way to push the repo to the jetson device, you could use server-side git hooks.

On the jetson device:

# create the remote workdir
mkdir -p /home/user/project/workdir

# create the remote repo
git -C /home/user/project init --bare repo

touch /home/user/project/repo/hooks/post-receive
chmod  x /home/user/project/repo/hooks/post-receive
nano /home/user/project/repo/hooks/post-receive
#!/bin/bash
while read oldrev newrev ref
do
  if [[ $ref =~ .*/master$ ]];
  then
    echo "Master ref received. Updating local work-dir ..."
    git --work-tree=/home/user/project/workdir --git-dir=/home/user/project/repo checkout -f
  else
    echo "Ref $ref successfully received; Not in master branch, so nothing to do."
  fi
done

On mac:

# Add the remote to the git repo:
git remote add jetson user@hostname:/home/user/project/repo/

git push jetson master
  • Related