Git Auto Sync
GitAutoSync is a simple command line program to automatically commit changes
to your git repo, and always keep that repo up to date. This way you can use any editor with your text files, and never need to worry about
comitting and remembering to push and pull changes.
Installation
- OSX -
brew install GitJournal/tap/git-auto-sync
- Linux -
-
Ubuntu/Debian -
sudo echo "deb [trusted=yes] https://apt.fury.io/vhanda/ /" | sudo tee /etc/apt/sources.list.d/git-auto-sync.list
sudo apt-get update
sudo apt-get install -y git-auto-sync
-
Fedora/RPM -
sudo echo -e "[git-auto-sync]\nname=Git-Auto-Sync\nbaseurl=https://yum.fury.io/vhanda/\nenabled=1\ngpgcheck=0" | sudo tee /etc/yum.repos.d/git-auto-sync.repo
sudo yum update
sudo yum install -y git-auto-sync
-
Arch Linux - Please write an AUR package and open a PR for this. You're an Arch User. You got this.
-
Other - Download the latest release
- Windows - Download the latest release
For the findingjimoh fork's safe worker release, pin installation to the tag:
go install github.com/findingjimoh/git-auto-sync@v0.1.0
How to use?
GitAutoSync comes with a manual and daemon mode. It's recommended to start with the manual
mode to ensure authentication is working correctly. It internally just calls the git executable
so, if that works, git-auto-sync should just work.
You can test it out by running git-auto-sync sync to commit, pull, rebase and push any changes.
If there are no changes, it will just attempt to pull, rebase and push.
Once you're satisfied that git-auto-sync is working for you. You can run git-auto-sync daemon add <repoPath> to start a background daemon which will continously monitor that repo for any changes
in the file system and accordingly sync the changes.
This daemon will be automatically started as a system process.
You can check if it is running git-auto-sync daemon status
Background Daemon
The background daemon will be started / stopped automatically if there are any repos to watch in git-auto-sync daemon ls.
This process will monitor the filesystem, poll every 10 minutes, and additionally try to sync on resuming from a suspend. The latter
two are done to pick up changes from the remote.
Merge Conflicts
GitAutoSync current only supports rebases, and doesn't yet attempt to do a merge. In the case of a
rebase conflict, it will abort and stop syncing that repo. It will send a system notification
to inform you of the conflict.
Ignored Files
It currently ignores all hidden files, files ignored by git, and additional temporary swap files
created by vim, emacs and similar editors.
Fork Changes (findingjimoh/git-auto-sync)
This is a fork of GitJournal/git-auto-sync with the following fixes:
Safe worker mode (v0.1.0)
Run one supervised worker for each checkout:
git-auto-sync watch \
--repo /absolute/path/to/repo \
--mode bidirectional \
--poll-interval 5s \
--command-timeout 60s
Use --mode pull-only for a consumer that may fast-forward a clean checkout but
must never stage, commit, or push. Pull-only mode fails closed when the checkout
is dirty or has local-only commits.
watch owns a kernel advisory lock for its entire lifetime. The lock file may
remain on disk after shutdown, but only the live kernel lock determines
ownership. A second worker exits before running any Git command. Filesystem
events feed one serialized one-second quiescence timer, while a separate ticker
polls the remote at the configured interval. Every Git subprocess has the
configured hard timeout.
Bidirectional cycles commit local changes, fetch the configured upstream,
rebase, and push. A rejected push is reconciled and retried. A true rebase
conflict is aborted, the local commit is preserved, publication is paused, and
macOS receives one notification for that pair of conflicting heads.
Machine-readable, credential-free health state is written atomically below
~/.local/state/git-auto-sync/. Inspect it through the supported interface:
git-auto-sync status --repo /absolute/path/to/repo
git-auto-sync status --repo /absolute/path/to/repo --json
Status includes the configured mode, heartbeat and successful-cycle freshness,
local and upstream heads, dirty/ahead/behind state, and the last classified
outcome. Health becomes stale after 20 seconds without a successful cycle.
Change discovery uses Git's NUL-delimited porcelain format, so empty files,
deletions, renames, spaces, and other valid path bytes are handled without
line-oriented parsing.
Environment inheritance fix (common/commit.go)
Upstream stripped all environment variables except HOME from git subprocesses. This broke tools like git-crypt that need to be in PATH. Fixed toEnvString() to inherit the full parent process environment when no custom env is configured (the default for daemon/watcher mode). When custom env IS set (via --env flag), it merges with the parent's HOME as before. Also fixed a double-append bug introduced in upstream commit 50cb029 that duplicated every custom env var.
Error resilience fix (common/watch.go)
Upstream used log.Fatalln() in the watch loop error handlers, which killed the entire process when any single repo failed to sync. Changed to log.Println() so errors are logged and the watcher retries on the next event or poll cycle, rather than crashing monitoring for all repos.
Explicit remote/branch in pull (common/autosync.go)
Changed git pull --rebase --autostash to git pull --rebase --autostash origin main to avoid "Cannot rebase onto multiple branches" errors when FETCH_HEAD contains entries from multiple fetch operations.
Similar Projects