In the last few weeks I had to create several GitHub repositories for my daily work. To simplify the process I automated the creation with PowerShell.
I created and initialized the repositories manually until I recognized that this is a perfect task to automate. First I studied the documentation of the GitHub API v3, which is very well documented! Fortunately for me the GitHub API supports all the functions I needed.
The automation contains the following steps:
- Create a new repository
- Initialize with one of the licenses provided by the license endpoint
- Initialize with one of the gitignore files provided by the gitignore endpoint
- Add a NOTICE file based on a predefined template to the repository
- Add the license shield to the readme if
Apache License 2.0
was selected as license - Add labels
feature
,onhold
andtask
to the repository
The PowerShell script that performs all the steps described above. The script, the corresponding configuration file and the README and NOTICE template can be found in the GitHub repository PS.GitHub.RepoCreator.
Feel free to use it and to contribute or create issues for desired use cases.
How to use
- Create an access token for command-line use (For details see here)
- Check out the sources from the
PS.GitHub.RepoCreator
repository - Navigate to the
src
folderConfig.xml
: Fill in your GitHub username and the access token generated in step 1NOTICE_Template
: Adjust the content according your wishes (IMPORTANT: The placeholdersREPONAME
andREPODESCRIPTION
always have to occur at least once in the file)README_Template
: Adjust the content according your wishes (IMPORTANT: The placeholdersREPONAME
,LICENSEBADGE
andREPODESCRIPTION
always have to occur at least once in the file)
- Now you’re ready to execute the script which will do the following
- Creation of a new repository with the selected license and the selected gitignore file
- In case you selected
Apache 2.0
as license, it will add a license badge to the README file - Creation of a NOTICE file based on the
NOTICE_Template
- Creation of 3 new issue labels:
feature
,onhold
,task
Sample invocation
PS C:\PS.GitHub.RepoCreator\src> .\New-GitHubRepo.ps1 -RepoName 'NAME' -RepoDescription 'DESCRIPTION'