Skip to content

Instantly share code, notes, and snippets.

@danielrosehill
Created May 10, 2025 20:10
Show Gist options
  • Save danielrosehill/df21009aca5037a8214e3cc5a13be43a to your computer and use it in GitHub Desktop.
Save danielrosehill/df21009aca5037a8214e3cc5a13be43a to your computer and use it in GitHub Desktop.
Setting up auto-pushes for YADM

YADM Repo Auto-push

This Gist includes:

  1. yadm-autopush.sh: A script that stages and commits tracked changes in your dotfiles and pushes them to your remote repository.

  2. yadm-autopush.service: A systemd user service that executes the yadm-autopush.sh script.

  3. yadm-autopush.timer: A systemd user timer that triggers the service every 6 hours, starting 5 minutes after boot.

Setup Instructions:

  1. Create the Script:

    Save the following content as ~/.local/bin/yadm-autopush.sh and make it executable:

    #!/bin/bash
    
    cd ~ || exit 1
    yadm add -u
    if yadm diff --cached --quiet; then
      exit 0  # Nothing to commit
    fi
    yadm commit -m "Auto-push: $(date +'%Y-%m-%d %H:%M')"
    yadm push

Make the script executable:

chmod +x ~/.local/bin/yadm-autopush.sh
  1. Create the Systemd Service:

    Save the following content as ~/.config/systemd/user/yadm-autopush.service:

    [Unit]
    Description=Auto-commit and push yadm dotfiles
    
    [Service]
    Type=oneshot
    ExecStart=/home/yourusername/.local/bin/yadm-autopush.sh

Replace /home/yourusername with your actual home directory path.

  1. Create the Systemd Timer:

    Save the following content as ~/.config/systemd/user/yadm-autopush.timer:

    [Unit]
    Description=Run yadm auto-push every 6 hours
    
    [Timer]
    OnBootSec=5min
    OnUnitActiveSec=6h
    Persistent=true
    
    [Install]
    WantedBy=default.target
  2. Enable and Start the Timer:

    Run the following commands to enable and start the timer:

    systemctl --user daemon-reload
    systemctl --user enable --now yadm-autopush.timer

To verify that the timer is active:

systemctl --user list-timers | grep yadm

This setup ensures that your yadm dotfiles are automatically committed and pushed to your remote repository every 6 hours, starting shortly after your system boots. If you need assistance customizing this setup further or have any questions, feel free to ask!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment