Git Product home page Git Product logo

gh-move-repos's Introduction

Move GitHub Repositories

You have to migrate your GitHub repositories from one organization to another? Or maybe you need to bulk move a bunch of archived repositories to a archive-only org without having to click through the web interface? This script automates the process of transferring repositories from one GitHub organization to another. It provides two possibilities: a simple BASH script or more versatile a Python implementation. Both check the results after the move.

Bash Script

The Bash script uses the gh CLI tool to transfer repositories. It assumes that you are already logged in to gh in your shell environment.

To use the Bash script:

Set your GitHub access token as an environment variable: export GH_TOKEN=your_github_token.

Run the script with a text file containing the names of the repositories to transfer: cat repos.txt | ./move_repos.sh <source_org> <dest_org>

The text file should contain one repository name per line.

Please note that both scripts transfer repositories from a source organization to a destination organization. You should replace source_org and dest_org in the scripts with the names of your source and destination organizations.

If you have owner permissions in an organization or admin permissions to one of
its repositories, you can transfer a repository owned by your organization to
your personal account or to another organization.

Python Script

The Python script uses the GitHub API to transfer repositories. It requires a GitHub access token, which should be set as the GH_TOKEN environment variable.

To use the Python script:

Install the required Python packages with pip install -r requirements.txt. Set your GitHub access token as an environment variable: export GH_TOKEN=your_github_token. Run the script with a text file containing the names of the repositories to transfer: python move_repos.py repos.txt.

โš ๏ธ The API call is aynchronous, meaning that it will return as soon as possible and then the transfer continues in the background. As of today, Github does not have a predetermined time for this task to complete so the check at point 2 may fail, especially if the repository is quite large. Increasing the SLEEP_TIME constant might do the trick.

Chaining

It is possible to launch this script from another script. For example, you can chain it in the following way:

python3 crawler.py -i org fospo -o print -f name archived > tmp.txt && \
python3 move_repos.py fospo dest_org tmp.txt && \
rm tmp.txt

In this way, for example, you will get all the repositories marked as archived in the organization fospo and move them to an organization of your choice.

Licensing

This repo is covered by a MIT License. See the LICENSE file for more details.

gh-move-repos's People

Contributors

libremente avatar

gh-move-repos's Issues

Run in parallel

Longer lists of repos to transfer might benefit from some parallelization :)

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.