Giter Club home page Giter Club logo

git-auto's Introduction

git-auto

A Simple Shell Script To Commit And Push Automatically

中文文档

Usage

Download the git-auto file

chmod +x git-auto
./git-auto

More samples:

git-auto # use current script dir as git dir, and auto commit, not push.
git-auto -d /path/to/your/note's/dir   # set git dir
git-auto -p # auto commit and push
git-auto -s origin -p # set remote server
git-auto -b main -p # set git branch
git-auto -i 30 -p # set interval seconds
git-auto -o -p # execute once

For Windows Users

Before you proceed to use the git-auto file, please make sure Git installed, otherwise please download Git and install it.

  1. Just click 'yes' all the way down and you will find Git Bash icon in the start.

  2. Open PowerShell

Download the target repository if you don't have it locally yet:

git clone [your_repo_url]
cd [your_repo_location]

For those who don't yet have a repository on Github, please refer to https://docs.github.com/en/github/getting-started-with-github/create-a-repo.

  1. Usage

Download the Start-GitAutoCommit.ps1 file, and run

.\Start-GitAutoCommit.ps1

More samples:

Start-GitAutoCommit # use current script dir as git dir, and auto commit, not push.
Start-GitAutoCommit -d /path/to/your/note's/dir   # set git dir
Start-GitAutoCommit -p # auto commit and push
Start-GitAutoCommit -s origin -p # set remote server
Start-GitAutoCommit -b main -p # set git branch
Start-GitAutoCommit -i 30 -p # set interval seconds
Start-GitAutoCommit -o -p # execute once

Contributors

Thanks for your work!

PowerShell Port, by @batkiz

Readme-CN.md & Git Bash docs, by @zhanghanduo

License

Copyright © 2020 Michael Wong

Distributed under the MIT License.

git-auto's People

Contributors

batkiz avatar danielgross avatar defclass avatar tallguyjenks avatar zhanghanduo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-auto's Issues

github上如果版本更新,而本地有了更改(如:自动生成了新日志)会出现无法pull的情况。

因为我在公司和家里都会使用logseq,但是如果在公司push完后回家打开logseq会出现无法pull的情况,对比过后发现打开logseq会更新本地一些meta数据,导致出现差异,需要手动合并,但是git-auto插件又无法合并,只能打开git手动进行命令行操作。

希望能处理下这个问题,或者指教下我的使用方式是不是不对。
谢谢。

How to run the Start-GitAutoCommit.ps1

Hello,

Usage:
git-auto ;; use current script dir as git dir, and Start-GitAutoCommitAnoPpush.
git-auto -d \OneDrive - DDV openBIM Solutions\DDV_PARA\3. RESOURCES\SOFTWARE\LOGSEQ ;; set git dir
git-auto -p ;; Start-GitAutoCommitAndPush
git-auto -s origin -p ;; set remote server
git-auto -b main -p ;; set git branch
git-auto -i 30 -p ;; set interval seconds
git-auto -o -p;; execute once`

Could someone tell a non-expert like me how to run the Start-GitAutoCommit.ps1 from Windows, as this repository instruction says?

'Usage
Download the Start-GitAutoCommit.ps1 file, and run

.\Start-GitAutoCommit.ps1'

thanks

macos usage + git pull?

What is the expected usage on macOS? Manually running the git-auto script on each boot? LaunchAgent?

Also, is it within the purview of this script to also pull the latest changes too?

I'm considering using this for iOS Sync via Working Copy.

Git Commit Hook Alternative

I just wanted to post a quick alternative to git-auto using a git post-commit hook and some gotchas I ran into while getting this set up. I like this approach because it ensures every commit is immediately pushed.

Creating post-commit hook

  1. Ensure your logseq database is a git repository. This usually entails running git init in the root of the logseq directory.
  2. Check "Enable Git auto commit" in the Logseq version control settings.
  3. Create the file .git/hooks/post-commit relative to the root of the logseq repository with the following contents:
    #!/bin/bash
    git push

Potential Gotchas

  1. On macOS, I usually use the osxkeychain for authentication using a "personal access token". This, for some reason didn't work out well and kept giving me the following error: fatal: could not read Username for 'https://github.com': Device not configured. I ensured that the script was being run as personal account, not root, but this didn't fix the issue. The easiest solution was to switch to using the git-credential-manager (GCM).

    # check if current credential.helper is osxkeychain
    ❯ git config credential.helper
    osxkeychain
    
    # clear osxkeychain password
    ❯ git credential-osxkeychain erase
    host=github.com
    protocol=https
    > [Press Return]
    
    # install latest git and git credential manager (GCM) from homebrew
    ❯ brew install git
    ❯ brew tap microsoft/git
    ❯ brew install --cask git-credential-manager-core
    
    # verify cask installation has automatically updated the credential.helper
    ❯ git config credential.helper
    /usr/local/share/gcm-core/git-credential-manager-core
    
    # attempt to git push, will bring up a pop-up establishing authentication
    git push
  2. For some reason, I was unable to change the hashbang for the post-commit hook. It seems to always use the system bash installed at /bin/bash (for me, version 3.2.57) even if I explicitly changed the hashbang to homebrew installed bash via #!/opt/homebrew/bin/bash. This means you can't use newer bash features like mycmd &>> /tmp/mylog etc.

    This longer script helped me debug all of these issues:

    #!/bin/bash
    mkdir -p /tmp/logseq/
    timestamp=$(date +"%s")
    filepath="/tmp/logseq/$timestamp"
    touch $filepath
    echo "attepmting push" >> $filepath
    echo "current directory: $(pwd)" >> $filepath
    echo "bash version: $(bash --version)" >> $filepath
    echo "whoami: $(whoami)" >> $filepath
    git remote -v >> $filepath 2>&1
    git push >> $filepath 2>&1

Hope this helps!

Add a date and timestamp to the commit message

I do the auto commits in intervals of 5 to 10 mins so I would like to know the time when the commit was made. So that I can track back the changes if I have to. It would make it easier a bit.

PowerShell port

a simple translation

param (
    [Alias('d')]
    [string] $Dir,
    [Alias('i')]
    [int] $Interval = 20,
    [Alias('p')]
    [bool] $AutoPush = $false,
    [Alias('o')]
    [bool] $Once = $false,
    [Alias('s')]
    [string] $Server,
    [Alias('b')]
    [string] $Branch
)

if ($Dir -ne "") {
    Set-Location $Dir
}

if ($Branch -eq "") {
    $Branch = (& git rev-parse --abbrev-ref HEAD)
}

function auto-commit-and-push {
    [string] $status = (& git status)
    if (!$status.Contains("working tree clean")) {
        git add .
        git commit -m "auto commit"
    }
    if ($AutoPush) {
        git push $Server $Branch
    }
}

Get-Date

if ($Once) {
    auto-commit-and-push
}
else {
    while ($true) {
        auto-commit-and-push
        Start-Sleep -Seconds $Interval
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.