Reputation: 3033
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
?
Upvotes: 1
Views: 795
Reputation: 762
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.
This proposal assumes that you want to edit the repo on mac
and want to push changes to jetson
for deployment. We will assume that you want to deploy the master branch of your repo to /home/user/project/deploydir
on jetson.
To achieve this, create deploydir
as well as a bare git repo on jetson
:
# create the remote deploydir
mkdir -p /home/user/project/deploydir
# create the remote repo
git -C /home/user/project init --bare repo
Next you need to setup the server-side git hook on jetson
:
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
Paste the following into the post-receive
hook script in nano. Basically, this will make sure that if you push a new master
ref to the repo, it will be checked out to the deploydir
:
#!/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/deploydir --git-dir=/home/user/project/repo checkout -f
else
echo "Ref $ref successfully received; Not in master branch, so nothing to do."
fi
done
Afterwards on mac
:
# Add the remote to the git repo:
git remote add jetson user@hostname:/home/user/project/repo/
# Push the master branch to jetson
git push jetson master
# Push the master branch to origin
git push origin master
The last statement assumes you have already a remote origin
defined in your repo which points to your Github repo.
Update, as you pointed out in the comments, that there will be code changes onjetson
:
In this case you can clone the repo on jetson to a local workdir on jetson:
cd /home/user/project
git clone /home/user/project/repo /home/user/project/workdir
Now, you have a local workdir on jetson
in which you can make code changes and push/fetch/pull to the bare repo.
You can sync your code changes between the workdirs on mac
and jetson
by pushing/fetching/pulling between these workdirs and the bare repo on jetson
. However, a sync between these two workdirs requires a command to be executed on both machines.
Every push to the master branch will be instantly checked out to deploydir
on jetson
, which might be useful to deploy changes to the location from where the code will be executed.
Upvotes: 1
Reputation: 1326666
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.
Upvotes: 0