This script automates the migration of local Git repositories to a new GitHub account by initializing the repositories (if not already initialized), creating corresponding repositories on GitHub, and pushing the contents to the new GitHub repository.
- Automatically initializes Git repositories if they aren't already initialized.
- Creates corresponding private repositories on a new GitHub account.
Before running this script, ensure that you have:
- Node.js installed on your machine.
- Git installed and available in your system's PATH.
- A GitHub account with a valid personal access token.
-
Clone or download the repository containing this script.
-
Install dependencies by running the following command:
npm install axios
-
Edit the following variables in the script to match your setup:
repoDir
: Set this to the path where your local repositories are stored.newUsername
: Your new GitHub account username.newToken
: Your GitHub personal access token. You can generate a new token in GitHub here.
-
Navigate to the directory containing the script.
-
Run the script using Node.js:
node bulkCreate.js
The script will:
- Loop through each directory in the specified
repoDir
. - Initialize a Git repository (if not already initialized).
- Create a private repository on GitHub for each local repository.
- Push all branches and tags to the newly created GitHub repository.
createRepo
function: This function uses the GitHub API to create a new private repository on your GitHub account.processRepositories
function: This function processes each local directory, initializes Git repositories (if necessary), creates the corresponding GitHub repository, and pushes the content to GitHub.
If the script encounters an issue while creating a repository or pushing content, an error message will be displayed for that specific repository, and the script will continue processing the remaining repositories.
- The script assumes that each folder in the specified directory represents a separate Git repository.
- Make sure that you have write access to the GitHub account and that your personal access token has the required permissions to create repositories and push code.
This script is licensed under the Apache License. See LICENSE.md for more details.