How to enable git auto-fetch?

I have several git projects that I want to receive every day (for example, in the morning) and checkout until the last commit (if there are local changes of course) does not belong to the "origin / dev" branch (for example, this cannot be the main branch). So how to do this for all the projects in the directory?

+5
source share
3 answers

How to do this for all projects in the catalog?

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

  • create a local repo in this directory
  • add all these Git repos projects as submodules (git add subodule -b dev url / git / repo / for / a / project): they will be configured to track the dev branch
  • every day (for example, with the cron task), do git submodule update --recursive --remote : this will git submodule update --recursive --remote and check the last from origin / dev for each submodule.

Note that the local repo in the directory acts as the β€œparent repo” for these submodules and is purely local: you do not need to push this repo. This is where you can use the submodule tracking feature introduced in Git 1.8.2+ (March 2013).

Your Git project repositories may completely ignore the fact that they are submodules for the parent directory repository.

In one command, you run fetch + checkout of the latest origin/dev for all of your Git projects.

+3
source

If you are using * nix / mac, you can 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 
+3
source

Maybe late for the party, but I wrote a tool for Windows and macOS to automatically fetch multiple repositories (and other functions):

Repoz

0
source

Source: https://habr.com/ru/post/1201995/


All Articles