How to turn on git auto-fetch?

我只是一个虾纸丫 提交于 2019-12-07 04:37:47

问题


I have several git projects which I want to fetch everyday (in the morning for example) and checkout to the last commit (if there are no local changes of course) to the branch "origin/dev" (e.g. it may not be a master branch). So how to do this for all projects in the directory?


回答1:


If you are using a *nix/mac you could use the following bash script and create a cron job/launchdaemon task:

#!/usr/bin/env bash
ls -d */ | while read folder; do
    if [ -d "$folder/.git" ]; then
        cd "$folder"
        git pull # CHANGE THIS TO YOUR NEEDS
        cd ..
    fi
done



回答2:


How to do this for all projects in the directory?

One way would be to (experiment in a separate local directory):

  • create a local repo in that directory
  • add all those Git repos projects as submodules (git add submodule -b dev url/git/repo/for/a/project): they will be set to track the dev branch
  • every day (with a cron job for instance), do a git submodule update --recursive --remote: that will fetch and checkout the latest from origin/dev for each submodules.

Note that the local repo in the directory act as a "parent repo" for those submodules, and is purely local: no need to push that repo. It is just there to benefit from the submodule tracking branch feature introduced in git 1.8.2+ (March 2013).

Your git project repos can ignore completely the fact they are submodules for the parent directory repo.

In one command, you trigger a fetch + checkout of the latest commits on origin/dev for all your git project repos.




回答3:


Might be late for the party but I wrote a tool for Windows and macOS to auto-fetch multiple repositories (and other features):



来源:https://stackoverflow.com/questions/25706866/how-to-turn-on-git-auto-fetch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!