- Python 98.2%
- Shell 1.8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| scripts | ||
| tests | ||
| .env.example | ||
| .gitattributes | ||
| .gitignore | ||
| .zipignore | ||
| git-pull-projects | ||
| git-pull-projects.py | ||
| README.md | ||
git-pull-projects
An interactive batch Git clone and update utility for GitHub and Forgejo. Run it from a parent project directory, select repositories from an account, review incoming changes, and deploy the selected projects locally.
Requirements
- Linux, Bash, Python 3.6+ with standard-library
curses, and Git 2.17+ (Ubuntu 18.04 target). - An interactive terminal (minimum 64 columns × 12 rows; 100+ columns recommended).
- A GitHub or Forgejo personal access token with read permissions. SSH keys or existing Git credentials are optional.
- No pip dependencies,
fzf, or build step.
The root Bash launcher runs the Python helper beside it, following the same architecture as deploy-project-update. Keep the entire project together.
Install
Extract the ZIP into a permanent directory, then run:
cd /path/to/git-pull-projects
./scripts/install.sh
This creates ~/.local/bin/git-pull-projects as a symlink to the launcher. It is safe to rerun; it refuses to replace unrelated files or symlinks. Optionally pass a different bin directory, e.g. ./scripts/install.sh /usr/local/bin (appropriate permissions required). Ensure that directory is in PATH. No root privileges are required for the default install. To uninstall, remove only the installed symlink.
Before you start
Create a personal access token:
- GitHub: a fine-grained token with access to the desired repositories, Metadata read and Contents read. A classic token with
reposcope also works for private repositories but grants broader permissions. Organization policies may require approval or SSO authorization. - Forgejo: use a personal access token with read access to user information and repositories (
read:user,read:repository; organization access may also requireread:organization). Exact scope names and availability depend on your version. Use the canonical instance URL (include the installation subpath, if any).
See GitHub repository API and Forgejo API usage.
Configure .env
Copy .env.example into the directory from which you will run the command, not necessarily the installation directory. Edit using vi .env and set restrictive permissions (chmod 600 .env). Never commit the token.
Forgejo example:
GIT_PULL_PROJECTS_PROVIDER=forgejo
FORGEJO_URL=https://forgejo.example.com
FORGEJO_TOKEN=your_token
GitHub example:
GIT_PULL_PROJECTS_PROVIDER=github
GITHUB_TOKEN=your_token
You can configure both providers in the same file and switch with -p github or -p forgejo. When exactly one provider-specific token is available, the provider is inferred if not explicitly configured. When both are available, choose a provider. A generic --token requires a selected or inferred provider.
The .env parser supports literal values, quotes, comments, and export KEY=value. It does not execute shell commands or expand variables. Configuration precedence is CLI, exported environment, current directory .env, then defaults. .env is always read from the original working directory, even when -o points elsewhere. Malformed assignments are rejected. Empty environment values are treated as unset.
Usage
git-pull-projects
git-pull-projects -p forgejo -o /opt/projects
git-pull-projects -p github --all
git-pull-projects -p github --org my-org --protocol ssh
git-pull-projects -p forgejo --forgejo-url https://forgejo.example.com --token YOUR_TOKEN
git-pull-projects --list
git-pull-projects -h
--all preselects all repositories on the first screen, but does not bypass either review or confirmation. --list lists repositories and local matches without fetching, cloning or changing checkouts. Prefer environment variables or .env over passing secrets on the command line (which may expose them to shell history or process listings).
| Option | Description |
|---|---|
-h, --help |
Show help. |
-o, --output DIR |
Existing output parent directory; default current directory. |
-p, --provider github|forgejo |
Select provider. |
--forgejo-url URL |
Forgejo base URL. |
--token, --api-key TOKEN |
Token for selected provider. |
--github-token TOKEN, --github-api-key TOKEN |
GitHub token. |
--forgejo-token TOKEN, --forgejo-api-key TOKEN |
Forgejo token. |
--username NAME |
Override HTTPS Git username; defaults to API login. |
--org NAME |
List a specific organization instead of account repositories. |
--protocol https|ssh |
New clone transport; default HTTPS. Existing repos keep their upstream. |
--auth token|git |
HTTPS auth: use API token (default) or normal Git credentials. |
--allow-http |
Explicitly permit insecure HTTP on self-hosted Forgejo. |
--all |
Initially select all repositories. |
--list |
Discovery only; works without interactive terminal. |
Environment variables
| Variable | Purpose |
|---|---|
GIT_PULL_PROJECTS_PROVIDER |
github or forgejo. |
GIT_PULL_PROJECTS_OUTPUT |
Destination directory. |
GIT_PULL_PROJECTS_PROTOCOL |
https or ssh. |
GIT_PULL_PROJECTS_AUTH |
token or git. |
GIT_PULL_PROJECTS_ORG |
Organization name. |
GIT_PULL_PROJECTS_ALLOW_HTTP |
Boolean; default false. |
GIT_PULL_PROJECTS_TOKEN |
Generic provider token. |
GIT_PULL_PROJECTS_USERNAME |
Generic HTTPS username. |
FORGEJO_URL |
Instance base URL; alias FORGEJO_BASE_URL. |
FORGEJO_TOKEN |
Forgejo PAT; alias FORGEJO_API_KEY. |
FORGEJO_USERNAME |
Forgejo HTTPS username. |
GITHUB_TOKEN |
GitHub PAT; aliases GITHUB_API_KEY, GH_TOKEN. |
GITHUB_USERNAME |
GitHub HTTPS username. |
1. Select repositories
The tool discovers the authenticated login and paginates the account repository endpoint (GitHub accessible repositories; Forgejo repositories returned by /user/repos). Use --org for a specific organization. It scans immediate child directories of the output folder and matches Git remote URLs against the selected provider. Repositories are sorted alphabetically by name and shown with owner, local status and archived status when relevant. The initial view always shows all account repositories. Matching local checkouts are automatically selected, including repositories in differently named directories. Press Enter to review them, or select additional repositories to clone. The scan uses the output directory (current directory unless overridden by -o or configuration). Only repositories returned by the configured account/API are eligible. Matching is based on remote identity, not just the folder name. A matching repository in a differently named folder is reviewed and updated in that existing folder. If several checkouts match, the canonical folder takes priority; otherwise ambiguous matches are blocked.
- Up/Down, Home/End, PgUp/PgDn: navigate.
- / or start typing: edit the search field; Enter/Esc exits search mode, Ctrl+U clears the query while editing.
- Space: select/deselect a highlighted repository outside search mode.
- Ctrl+A: select all visible results; Ctrl+D: clear all selections.
- Enter: check selected repositories and build review.
- Esc: cancel outside search mode.
Selections persist when searching or returning from review. The first screen starts with matching local repositories checked. --all instead selects every repository. Ctrl+A selects all visible search results. An absent folder is not proof of an available clone; the second screen evaluates actions.
2. Review projects
The program fetches the upstream tip for each selected existing checkout and compares it with the current branch. It does not change working-tree files at this point. Fetch may update FETCH_HEAD, remote-tracking refs and Git objects even if you later cancel. For new repositories, the tool fetches the default branch into a temporary bare Git repository to show its complete tracked file tree and file contents. This downloads Git objects before confirmation, but creates no destination checkout. Temporary previews are removed when leaving review or exiting normally.
| Status | Meaning |
|---|---|
| CLONE | Destination absent; new checkout. |
| UPDATE | Clean local branch can fast-forward to the fetched tip. |
| CURRENT | Current local branch already matches upstream. |
| AHEAD | Local-only commits; no pull performed. |
| DIVERGED | Both local and upstream commits; manual reconciliation required. |
| DIRTY | Incoming changes exist but tracked or untracked local changes block the update. |
| BLOCKED | Name collision, wrong remote, invalid repository, missing upstream, detached HEAD, Git error, etc. |
All actionable CLONE and UPDATE projects are selected by default. Other statuses cannot be selected. Existing checkouts retain their current branch and configured upstream, including non-origin remotes. The split-pane preview shows an expandable project/file tree on the left and the highlighted project details or file diff on the right. It reports incoming and ahead commit counts and changed-file counts. Diffs are colored and wrapped to fit the right pane. Renames appear as delete/add pairs. Diverged branches show changes from the merge base. New clones display the remote file tree and full UTF-8 text contents instead of a diff. Binary, non-UTF-8 and files larger than 1 MiB show a notice; submodules are listed but not fetched.
- Continue (top row): press Enter to open final confirmation. The cursor starts on this row.
- Back to repositories (second row): press Enter to return to the first screen; Esc also goes back. The repository search, selections and review choices are preserved when returning; upstream status is fetched again.
- Space: toggle the highlighted project.
- Right/Left: expand/collapse a project or directory. Left from a file moves to and collapses its parent.
- Up/Down: highlight files to display their diffs or new-file contents immediately, without opening a separate screen.
- Tab: switch keyboard focus between the tree and diff. Enter on a file also focuses its diff; Enter in the diff returns focus to the tree.
- Diff pane: Up/Down, PgUp/PgDn, Home/End scroll wrapped lines; Left/Right jump between hunks.
- Ctrl+A / Ctrl+D: select all actionable / deselect all.
- A: shortcut to final confirmation; Esc: return to repository selection.
The diff is informational; individual files cannot be excluded from a Git update. Git integrates whole commits, not individual selected files. Binary files may only show a binary-diff notice.
3. Confirm and deploy
The confirmation lists every selected clone and update, with the count of incoming commits for each update. Use arrow keys to scroll and press Y to execute. N, Enter or Esc defaults to no and returns to review.
Projects run sequentially with an individual success/failure summary. Exit status is 0 for success/cancellation, 1 for errors or partial failure, 130 for interruption. No automatic rollback of already completed projects is attempted.
Safety and authentication
- New destinations must not exist. The tool reserves the directory before cloning without checkout, verifies that the cloned HEAD matches the reviewed commit, then checks out the files. If the remote changes, the checkout is stopped and the reserved Git directory is left for manual inspection. It never recursively deletes destination data after a failure. If an interrupted or failed clone leaves files, inspect them manually.
- Updates are fast-forward-only. The tool rechecks branch, HEAD, upstream, working tree, and fetches again before applying the exact reviewed commit. If the remote changed after review, rerun and inspect the new diff. This is equivalent to a guarded
git pull --ff-onlyusing the current branch's upstream. Ignored files that would be overwritten are protected by--no-overwrite-ignore. Do not concurrently edit or run Git commands in these repositories during deployment. - Dirty, diverged, detached, missing-upstream, mismatched-remote, symlink and ordinary-folder cases are not overwritten. It does not reset, stash, rebase, push, force checkout or replace remotes. A dirty checkout with no incoming commits may be shown as CURRENT/AHEAD; it remains nonactionable.
- HTTPS token mode uses a scoped Git askpass helper, not a token in the clone URL, Git config or remote. It only provides credentials for the API instance's expected HTTP(S) origin (github.com for GitHub), disables credential-helper persistence and refuses redirects. It does not log tokens intentionally. Exported secrets remain available to processes in the normal environment; use trusted repositories/configuration and protect your token.
--auth gitleaves existing Git credential helpers/askpass configuration in charge. Use a noninteractive credential helper. SSH uses your existing keys, agent, and SSH config; ensure connectivity and host verification are set up beforehand. SSH aliases whose URLs do not match API-advertised identities are conservatively blocked. For instances advertising a different HTTPS clone origin, use--auth gitor SSH.- TLS verification is not disabled. Insecure HTTP requires explicit opt-in. The API token is still required for discovery with SSH or native Git auth. HTTPS Git credentials use the API token as the password unless native authentication is selected.
- No automatic submodule initialization or recursive updates; ordinary Git filters, hooks and local Git config may affect Git operations. Clone hooks are disabled for the token-bearing clone invocation. Use trusted repos and local Git configurations. Repository checks are sequential; new clone previews download the default branch history into temporary storage, and the final clone downloads again. Large repositories or slow remotes can take time. API request timeout is 30 seconds; individual Git commands have a 180-second timeout.
Tests
python3 -m unittest discover -s tests -v
Tests use mocked API pagination and isolated real Git repositories served over authenticated local HTTP; no external account or credentials are required. The test HTTP server requires Python 3.7+ (the application targets Python 3.6+). Test coverage includes cloning, credential handling, current/dirty/ahead/diverged branches, incoming file previews, remote changes after review, name collisions and configuration precedence. Live GitHub/Forgejo account access and the Ubuntu 18.04 runtime must be verified in your environment.