The solution to my question is the following
Use with AIg = Github(token)
user = g.get_user()
repo = user.create_repo(full_name)
Answer from ustroetz on Stack OverflowHow do I create a remote git repository on my github account with python or push a local git repo to my github account using python? - Stack Overflow
python - How to create a new repository with PyGithub - Stack Overflow
python - Bash script to create new GitHub repository from template - Stack Overflow
How to properly configure a Python project as a github repository
The solution to my question is the following
Use with AIg = Github(token)
user = g.get_user()
repo = user.create_repo(full_name)
I stumbled across this question trying to figure out how to coax PyGithub into creating a Repository within an Organization and thought it would be relevant here.
Use with AIg = Github(token)
organization = g.get_organization("org-name")
organization.create_repo(
name,
allow_rebase_merge=True,
auto_init=False,
description=description,
has_issues=True,
has_projects=False,
has_wiki=False,
private=True,
)
The full set of keyword arguments may be found here: https://developer.github.com/v3/repos/#input
Hello all, i write often in Medium for topics about Python and Linux! in this article i describe how someone can configure a Python project as a github repository properly
https://medium.com/python-in-plain-english/python-how-to-properly-configure-a-project-as-github-repository-ae207238a713
Since there would be people that do not have medium subscription i post my article here as well, but if anyone wants to support me please read the article on medium and click "clap" :)
Python: How to Properly Configure a Project as a GitHub Repository
Usually when we work on Python projects we create virtual environments per project, those files are not needed under version control so it doesn't make sense to include them to the repository files, also configuring the project to push changes to remote repositories might be something trivial to experienced developers but new developers might struggle to do the configuration. In this article i will show you how to perform a Python project properly as Github repository, lets start!
Part 1: Create SSH keys for Github
My favorite and most straight forward way for me to authenticate with Github is with the usage of SSH keys, the procedure is to create a pair of private and public keys from our host and then copy the public key to Github, Then the git tool will use the private key to authenticate vs Github and perform all the needed actions to the remote repository, lets create our keys first.
WARNING: if you already have a pair of keys named id_rsa and id_rsa.pub on your ~/.ssh directory will overwrite your existing keys, so use with care!
$ ssh-keygen
Press enter on any prompts that will appea
Part 2: Copy the public key to your Github account
Goto:
Account Settings → SSH and GPG keys → Click on the “New SSH key” Button
Paste your public key here and give a Title, then Click “Add SSH key”
You are done! Github is not accepting Authentication requests using the key you created.
Part 3: Create and clone the repository
Create a new repository on Github, then click on “Code” → “SSH” and copy the git@github.com:<user>/<repository> parameter
Now on your computer open a terminal and enter
git clone git@github.com:kpatronas/test01.git
This will clone the repository to your computer ready to configure it for you Python project!
Part 4: Configure the Python virtual environment
A virtual environment is a sandbox that has its own Python and Installed Python libraries, its a very good practice that allows you to have separate environments with different library versions, to create a virtual environment for this project type the following:
Enter the repository directory
cd test01
Then create the virtual environment
virtualenv venv && cd venv
And finally install needed libraries, in this example i did the following
activated the virtual environment for this project using the source ./bin/activate command
install the fastapi Python library just for example. moved out the venv directory and created a requirements.txt file if the libraries installed to this environment, this is needed so the next guy who will clone our project will be able to install all the needed libraries using the pip command
source ./bin/activate pip3 install fastapi cd .. pip3 freeze > requirements.txt
Part 5: Configure git properly
Next step here is to exclude things that we dont want under version control, one of those things are the virtual environment, is something that everyone can create since the requirements.txt exists, inside yor repo directory enter
echo 'venv' > .gitignore
What we just did is to enter the virtual environment directory name to .gitignore file, this file instructs git what files or directories to exclude from tracking
Part 6: First commit
Lets do our first commit to the repository , using git add we instruct git that we want to include all files under version control using the “.”
git add .
Now we are going to perform our first commit
git commit -m "First Commit"
And finally time to perform our push to the remote repository
git push -u origin main
The push should be completed without problems!
We can verify this by visiting the webpage of our github repository, we can verify that the requirements.txt exist but the virtual environment no!