Skip to content

xilinqie/GitHub-Auto-Commit-Script

Repository files navigation

GitHub Auto Commit Script ==for MACOS==


Example

This repository provides a Bash script that automatically commits and pushes multiple local Git repositories.
It is designed for scenarios such as daily learning notes, research backups, or log synchronization.


📌 Features

  • 🔄 Support multiple repositories at once
  • 🕒 Auto-generate commit messages with timestamps
  • 📝 Write logs for each repository
  • 🛠️ Easy to extend (just add new repositories to the list)

📂 Repository Structure

.
├── README.md                 # Documentation
├── auto_commit_example.sh    # Example script to auto-commit/push multiple repos
├── LICENSE                   # License
├── .gitignore                # Ignore rules (includes macOS/AppleDouble files)
└── example.png               # Example screenshot used in README

Note: System-generated files (e.g., ._* files) and user-specific sample files (e.g., under ~/Library/LaunchAgents) are intentionally omitted.

the example script

#!/bin/bash
cd "the path of the directory you want to push"
git add .
git commit -m "auto-commit: $(date '+%Y-%m-%d %H:%M:%S')"
git push -u origin main
echo "Success at $(date)" >> the path of the log file

cd "another path"
git add .
git commit -m "auto-commit: $(date '+%Y-%m-%d %H:%M:%S')"
git push -u origin main
echo "Success at $(date)" >> another log file path

#...you can add more repositories, the format is the same

the explanation of the script

  1. #!/bin/bash: This line specifies the interpreter to use for the script, which is Bash.
  2. cd "the path of the directory you want to push" This line changes the current directory to the specified path.
  3. git add . This line stages all changes in the current directory for the next commit.
  4. git commit -m "auto-commit: $(date '+%Y-%m-%d %H:%M:%S')" This line commits the staged changes with a message including the current timestamp.
  5. git push -u origin main This line pushes the committed changes to the remote repository named "origin" on the "main" branch.
  6. echo "Success at $(date)" >> the path of the log file This line appends a success message with the current timestamp to the specified log file.

🔧 How to Use

  1. step1:

    nano /Users/yourusername/auto_commit.sh
    • add the script to the file
    • save the file
    • exit the editor
  2. step2:

    chmod +x /Users/yourusername/auto_commit.sh
    • make the script executable
  3. step3:

    nano ~/Library/LaunchAgents/com.yourusername.auto_commit.plist
    • create the plist file
  4. step4:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.yourusername.auto_commit</string>
        <key>ProgramArguments</key>
        <array>
            <string>/Users/yourusername/auto_commit.sh</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartCalendarInterval</key>
        <dict>
            <key>Hour</key>
            <integer>4</integer>  <!-- 北京时间凌晨4点 -->
            <key>Minute</key>
            <integer>0</integer>
       </dict>
        <key>StandardOutPath</key>
        <string>/Users/yourusername/auto_commit.log</string>
        <key>StandardErrorPath</key>
        <string>/Users/yourusername/auto_commit.error.log</string>
    </dict>
    </plist>
    • save the file
    • exit the editor
  5. step5:

    launchctl load ~/Library/LaunchAgents/com.yourusername.auto_commit.plist
    • load the plist file
  6. step6(OPTIONAL):

    launchctl start com.yourusername.auto_commit
    • run the script once right away
  7. step7(OPTIONAL):

    cat /Users/yourusername/auto_commit.log
    • check the log file

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages