Search code examples
pycharmgithub-cli

Is it possible to change, clone directory, when creating repo using GitHub CLI?


I use PyCharm to work on my Python projects, and I use the standard procedure of creating the project

Open Pycharm -> New Project -> Specify the Location -> Specify "New Virtualenv environment" -> Create

Now from this directory, I use GitHub CLI to create my repo on github like so

gh repo create MyProject

These are the prompted options

? Visibility Public                               
? Would you like to add a .gitignore? Yes   
? Choose a .gitignore template Python                                  
? Would you like to add a license? No    
? This will create the "MyCoolProject" repository on GitHub. Continue? Yes   
✓ Created repository Razvi/MyProject on GitHub
? Clone the remote project directory "Razvi/MyProject"? (Y/n)

The last question when answered "Yes" clones the remote project directory by creating new directory in the existing directory like so

Default

What I would like is to bypass the redundant "MyProject" directory (marked red) inside the initial "MyProject" directory (marked green).

Expected

How do I change that?


Solution

  • You can do it by initializing the directory before creating the repo

    Create a Python Project in PyCharm as usual.

    1. Initialize your project directory as main git branch using

      git init -b main
      
    2. Create your repo using GitHub CLI

      gh repo create MyProject
      

      You will have the following options

      ? Visibility Public                               
      ? Would you like to add a .gitignore? Yes   
      ? Choose a .gitignore template Python                                  
      ? Would you like to add a license? No    
      ? This will add an "origin" git remote to your local repository. Continue? Yes
      

      This will create the repo with .gitignore file at the main directory level.

    3. Now pull the main branch using

      git pull origin main
      

    You have your project set-up as required.