Lightweight CLI for scanning local Git repositories and cloned repos from JSON.
Features
- Scan a directory tree for Git repositories and export a summary to JSON.
- Clone repositories from a JSON export into a target directory.
- Preserve branch information when cloning; detached heads are marked.
- Rust (cargo)
- Git
Build the binary using cargo:
cargo build --releaseInstall locally:
cargo install --path .The CLI supports two subcommands: scan and clone.
Scan a root directory and export repositories to JSON:
codesync scan --root ~/hdev/workspaces --depth 5 --output repos.jsonOptions:
--root(string): Root folder to scan. Defaults to~/hdev/workspaces.--depth(usize): Maximum depth to traverse when searching for.gitdirectories. Defaults to5.--output(string): Output JSON filename. Defaults torepos.json.
Clone repositories defined in an export JSON into a target folder:
codesync clone --input repos.json --target ~/codespaceOptions:
--input(string): Path to a JSON file exported byscan. Defaults torepos.json.--target(string): Directory where repositories will be cloned. Defaults to~/codespace.
The exported file is a list of objects with the following shape:
[
{
"path": "relative/path/to/repo",
"origin": "git@github.com:example/repo.git",
"branch": "main"
}
]path: Relative path to the repository (relative to--rootused during scanning).origin: Theoriginremote URL for the repo.branch: The current branch ordetachedif HEAD was detached.
scanlooks for.gitdirectories under--root. Repositories without anoriginremote are skipped.scanstores paths relative to the provided--rootargument.clonecreates parent directories if needed and skips cloning if a.gitfolder already exists.- If a branch is not
detached,cloneattempts togit checkoutthat branch after cloning.
- Ensure
gitis installed and accessible in yourPATH. - If cloning fails for a repo, it will be reported and the CLI continues with the next repo.
- For private repositories, ensure you have correct SSH keys or appropriate authentication configured.
This repository does not include a license file. Add a LICENSE if you wish to define reuse terms.
Contributions are welcome. Open an issue or a pull request with suggested changes or fixes.
If you want to push this project to a remote repository (for example GitHub), run:
git remote add origin git@github.com:your-username/your-repo.git
git branch -M main
git push -u origin mainReplace git@github.com:your-username/your-repo.git with your remote repository URL.
You can produce macOS binaries for both Intel (x86_64) and Apple Silicon (aarch64), then create a universal binary.
Local build steps (macOS):
# Build for Intel
rustup target add x86_64-apple-darwin
cargo build --release --target x86_64-apple-darwin
# Build for Apple Silicon
rustup target add aarch64-apple-darwin
cargo build --release --target aarch64-apple-darwin
# Combine with lipo
lipo -create \
target/x86_64-apple-darwin/release/codesync \
target/aarch64-apple-darwin/release/codesync \
-output dist/codesync
chmod +x dist/codesync
zip -j dist/codesync-macos-universal.zip dist/codesyncOr use the convenience script:
scripts/build_macos_universal.shCI (GitHub Actions):
- A workflow is included at
.github/workflows/release-macos.ymlwhich builds both architectures on macOS runners, creates a universal binary, and publishes it when a tag is pushed (for examplev1.0.0).
Signing and notarization
- For distributing outside the App Store, consider signing and notarizing the binary. This requires a Mac developer account and the Apple notary tools; those steps are not included in this repository but can be integrated into the release workflow.