You are welcome to contribute to this repo. See the CONTRIBUTING.md for more info.
A full tutorial walking you through this program is detailed on the inspirezone.tech blog post: Github API use case: Automate git local and remote repo setup with Python.
The repo source files have gone through major modifications since the tutorial was written. You can see the original tutorial files under the folder blog-tutorial-original-code/. Use the code found in this folder to follow along with the blog tutorial.
About this repo
Automate creation of a local repo on your PC and a remote repo on Github.
One a single run of the script it will:
- Init a local repo
- Create a file in the repo
- Commit the file
- Create a repo on Github using same name as local repo
- Get origin URL for created repo on Github
- Push local repo to Github repo
Step 1: Install Curl
Curl is a command line tool for transferring data using network protocols such as HTTPS. We use this tool to interact with the Github API.
For Ubuntu systems curl can be installed by running:
sudo apt-get install curl
For other systems see the curl installation guidelines
config.ini fileStep 2: Setup the
Fill in your settings before running the script. An example configuration:
[your_settings] ; enter your github token for authorization purposes github_token = 0000111122223333444455556666777788889999 ; directory to create the repo on your computer directory = /pathto/yourfolder/ ; name of the repo repo_name = your_repo_name ; first committed file commit_file = README.md ; first commit message first_commit_msg = first commit ; your github user name github_name = your_github_name ; optional final command to run in repo directory e.g. "code ." cmd = code .
The github_token is a personal access token generated from your Github account. It allows you to authenticate to Github when using the API. Follow the Github docs instructions on how to generate a personal access token.
Step 3: Run the script
Run python script using
Running the test program using pytest
test_automate_git.py is used to execute a test program to check basic functionality of the application.
To run the test do the following:
pip install -r requirements.txt
Execute the test program