Skip to main content

GithubActions ReadTheDocs Pypi Downloads Codecov

The git_sync module.

Github

https://github.com/Erotemic/git_sync

Pypi

https://pypi.org/project/git_sync

This is a very simple git script to help with local development and remote execution. It turns the process of commiting, logging into the remote machine, and then pulling on the remote machine into a single command.

Assuming that you have the same file structure on both your local and remote machine, git-sync allows you to edit files locally, and when you want those changes reflected on the remote machine, you execute

git-sync other-machine

Note, that this creates a commit with the message “wip” and pushes it to the default git-remote. The commit message and target git-remote can be modified by command line args.

Installation

Installing the git_sync Python module also installs the git-sync command line utility.

pip install git-sync

Details

Executing git-sync performs the following actions:

  1. Executes a git commit to the local repo (the default commit message is “wip”, but this can be changed using the -m flag).

  2. Executes a git push origin which pushes the local copy of the repo to the git server. (Note, git-sync defaults to the origin git remote, but you can specify a different one using a second positional argument: e.g. git-sync other-machine remote2).

  3. Creates an SSH connection to “other-machine”, cd’s into the same directory you are in on the local machine (which is why mirroring the directory structure across development machines is important), and then executes a git pull origin, which will update the remote machine to the newly pushed state.

Caveats

Note that this script is very simple, it will fail if these conditions aren’t met.

  • The location of the repo (relative to the home directory) must be the same on the local and remote machine. Note, it is fairly easy to ensure this is the case using symlinks.

  • The repo on the local machine and remote machine must be on the same branch.

  • The repo on the remote machine must be in a clean state.

On SSH Configs

Also, to make life easier, it is best that you have a $HOME/.ssh/config file setup with the remote machines you to access and appropriate identify files so you don’t need to enter your password each time you git-sync.

An example ssh config entry is:

Host {myremote} {myremote.com}
    HostName {myremote.com}
    Port 22
    User {username}
    identityfile ~/.ssh/{my_id_ed25519}

Replacing any entry in {curly braces} with an appropriate value.

If you don’t have an ssh identify file, create one using:

mkdir -p $HOME/.ssh
cd $HOME/.ssh

FPATH="$HOME/.ssh/my_id_ed25519"
ssh-keygen -t ed25519 -b 256 -C "${EMAIL}" -f $FPATH -N ""

chmod 700 ~/.ssh
chmod 400 ~/.ssh/id_*
chmod 644 ~/.ssh/id_*.pub

And ensure the public key is registered with the remote machine:

REMOTE={myremote.com}
REMOTE_USER={myusername}
ssh-copy-id $REMOTE_USER@$REMOTE

Similar Software

  • CFarm is a tool for keeping remotes in sync and testing code on the remote machines.

  • Visual Studio Code has great remote ssh and developing support.

Release files for git-sync 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-sync 0.2.0
File Size Uploaded
git_sync-0.2.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for git-sync 0.2.0
File Interpreter ABI Platform
git_sync-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / git_sync-0.2.0.tar.gz

Download URL git_sync-0.2.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ab9f280995970b70ec937dde6e168180adf461f336e77ef7f058196587d6faba
BLAKE2b-256 checksum
How to use checksums
3d778a0e79ca611eb0a636e612c83e8ab02efdd44d1f4fe7f0a779380c7008ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release files / git_sync-0.2.0-py3-none-any.whl

Download URL git_sync-0.2.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5786fb64383e39149179d17ba05eeaf8d7ca0f5191a8f48f9ac910d41090c25e
BLAKE2b-256 checksum
How to use checksums
fd7cfba5ecc37c98ebb7280e0205becd3bc70bf87a2b4335959db5fefd0d9b96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page