This plan outlines a C# console application that automates updating multiple GitHub repositories based on instructions from a CSV file.
The utility will:
- Parse a CSV configuration file that groups changes by repository (each repo with its list of files to update).
- Authenticate to GitHub using a Personal Access Token (PAT) for non-interactive, secure access.
- Clone repositories (if not already local) or pull the latest changes for existing clones, ensuring the local copy is up-to-date.
- Copy specified files from a source location into each target repository, adding any new files and updating tracked files as listed (ignoring any files not specified).
- Stage and commit the changes in each repository.
- Use commit messages supplied in the CSV or generate them using Azure OpenAI.
- Push commits back to GitHub on the appropriate branch.
- Log all actions and errors to the console.
- Run as a standalone console application suitable for Task Scheduler, cron, or on-demand execution.
The application follows a modular architecture.
Responsible for:
- Reading and parsing the CSV file.
- Grouping file changes by repository.
- Producing a collection of repository tasks.
Responsible for:
- Clone operations.
- Pull operations.
- Staging files.
- Creating commits.
- Pushing changes.
Implementation options:
- LibGit2Sharp
- Git CLI
Responsible for:
- Copying source files into repositories.
- Creating required directory structures.
- Detecting new versus existing files.
Responsible for:
- Using commit messages provided by the CSV.
- Generating commit messages via Azure OpenAI when not supplied.
- Falling back to a default message if generation fails.
Responsible for:
- Console output.
- Error reporting.
- Timestamping.
- Operational tracing.
Program.Main() orchestrates:
- Load configuration.
- Process each repository.
- Clone or pull repository.
- Copy files.
- Stage files.
- Generate commit message.
- Commit changes.
- Push changes.
- Log results.
Repository failures are isolated so processing continues for remaining repositories.
The CSV uses one row per repository.
Repository,Branch,CommitMessage,File1,File2,File3,...GitHub repository URL or repository identifier.
Example:
https://github.com/Org/RepoName.git
Optional target branch.
Examples:
main
dev
release
If omitted, the default branch is used.
Optional commit message.
If empty, Azure OpenAI generates one.
Files to copy into the repository.
Examples:
README.md
docs/CONTRIBUTING.md
src/Lib/Helper.cs
Repository,Branch,CommitMessage,File1,File2,File3
https://github.com/ExampleOrg/RepoA.git,main,"Update project docs",README.md,docs/CONTRIBUTING.md,images/logo.png
https://github.com/ExampleOrg/RepoB.git,,,"src/Lib/Helper.cs","src/Lib/Utils.cs","config/appsettings.json"class RepoTask
{
public string RepoUrl;
public string Branch;
public string CommitMsg;
public List<string> Files;
}The utility uses a GitHub Personal Access Token (PAT).
Recommended:
- Environment variables
- Secret stores
- Secure configuration files
Example:
export GITHUB_TOKEN=<token>new UsernamePasswordCredentials
{
Username = "git",
Password = token
}git clone https://USER:TOKEN@github.com/Org/Repo.git- Non-interactive
- Script-friendly
- Fine-grained permissions
- Easily rotated
Example:
working/
├── RepoA
├── RepoB
└── RepoC
If repository does not exist locally:
git clone
or
Repository.Clone(...)git clone -b mainor
CloneOptions.BranchNameIf repository already exists:
git pullor
Commands.Pull(...)Possible actions:
- Retry pull.
- Log conflict.
- Skip repository.
- Continue processing others.
Example:
C:\RepoUpdates
File paths provided directly in CSV.
For each file:
- Locate source file.
- Build destination path.
- Create destination directories.
- Copy file.
- Stage file.
Example:
File.Copy(source, destination, true);Commands.Stage(repository, filePath);git add file.extIf no files changed:
No changes for RepoX; skipping commit.
Examples:
File not found.
Permission denied.
Copy failed.
Repository processing can be skipped if required.
The utility supports two approaches.
Example:
Update project documentation
Used exactly as supplied.
AZURE_OPENAI_KEY
AZURE_OPENAI_ENDPOINT
AZURE_OPENAI_MODEL
Generate a short commit message for:
- Added README.md
- Updated appsettings.json
Add README and update configuration settings
Automated update commit
Example:
Automation Bot <bot@example.com>
repository.Commit(
commitMessage,
authorSignature,
committerSignature);git commit -m "Update project docs"If no changes exist:
No changes to commit.
repository.Network.Push(...)git push origin mainPossible retry when:
- Remote branch advanced.
- Pull required before push.
- Invalid PAT
- Permission issues
- Network failures
- Merge conflicts
Pushed changes to RepoA
[2025-03-04 08:00:00] INFO: Cloning repository 'RepoA'
[2025-03-04 08:00:10] INFO: Repository cloned
[2025-03-04 08:00:11] INFO: Copying files
[2025-03-04 08:00:12] INFO: File copied
[2025-03-04 08:00:13] INFO: Commit created
[2025-03-04 08:00:15] SUCCESS: Push complete
ERROR: CSV file not found
ERROR: Authentication failed
ERROR: Missing source file
ERROR: Push rejected
Each repository is processed independently:
try
{
ProcessRepository();
}
catch
{
LogError();
}
Processing continues even if one repository fails.
0
1
AutoGit.exe "C:\configs\repos.csv"Recommended for Windows environments.
Recommended for Linux environments.
Examples:
- GitHub Actions
- Jenkins
- Azure DevOps
GITHUB_TOKEN
AZURE_OPENAI_ENDPOINT
AZURE_OPENAI_KEY
AZURE_OPENAI_MODEL
- GitHub repository access
- Network connectivity
- Local file system access
The AutoGit utility automates repository maintenance by:
- Reading repository instructions from CSV.
- Cloning or updating repositories.
- Copying managed files.
- Staging changes.
- Generating commit messages.
- Committing updates.
- Pushing changes to GitHub.
- Logging all activity.