1

How to use github cli to auto pull all newly created or updated repos to local pc?

I think I need to listen for new repo creation/updation and pull the repos. How to do it with cli?

If can't listen, I need to pull latest 100 repos to local machiene. How to do it?

I tried https://api.github.com/users/xxxx/repos?per_page=100. It gives in alphabetical order.

I use following code

 #!/bin/sh                                                                       
    cat repolist.txt | while read line                                              
     do                                                                              
     REPOSRC=$line                                                                   
     LOCALREPO=$line                                                                 
                                                                                     
     # We do it this way so that we can abstract if from just git later on           
     LOCALREPO_VC_DIR=$LOCALREPO/.git                                                
                                                                                     
     if [ ! -d $LOCALREPO_VC_DIR ]                                                   
    then                                                                            
       cd ~/xxxx                                                                
       gh repo clone $REPOSRC                                                       
       cd ~                                                                         
    else                                                                            
       cd ~                                                                         
       gh repo sync $REPOSRC -s $REPOSRC                                            
    fi                                                                              
    done                                                                            
    # End 
Bsde
  • 146
  • 1
  • 2
  • 10
  • [Show us](https://stackoverflow.com/help/minimal-reproducible-example) the code you've written so far, even if it does not yet retrieve the desired repos properly. – J_H Jan 06 '23 at 02:58
  • updated with code. How to listen to new addition/updation of repo? Or is there any autosync feature? – Bsde Jan 06 '23 at 04:52

1 Answers1

1

The sort key you're looking for seems to be sort=pushed.

Try curl -s 'https://api.github.com/users/xxxx/repos?sort=pushed&per_page=100' | jq '.[].name' to verify.

J_H
  • 17,926
  • 4
  • 24
  • 44