Learn how to create Github repositories using Github Cli without ever accessing the Github website. Follow this guide to streamline your workflow and enhance your project management skills.
Github Cli is a command-line tool that brings Github to your terminal. Here's how you can install it:
brew install gh
scoop install gh
sudo apt install gh
These commands will install Github Cli on your system.
With Github Cli, creating a new repository is a breeze. Follow these steps:
First, authenticate your Github account by running:
gh auth login
You can create a new repository by using:
gh repo create my-new-repo --public
Output:
✓ Created repository user/my-new-repo on GitHub
This command creates a public repository named 'my-new-repo' under your account.
To push your code to the newly created repository, use:
git push origin main
This command pushes the code to the 'main' branch.
Setting up a new project often involves several repetitive tasks such as creating a new directory, initializing a Git repository, and linking to Github. To simplify these tasks, we have developed automated scripts for macOS, Linux, and Windows. These scripts combine several steps into one, providing a convenient way to quickly initiate new projects.
For macOS and Linux users, the following bash script streamlines the process of creating a project directory, initializing a local Git repository, creating a corresponding private Github repository, and connecting them.
#! /bin/bash
echo 'Create a project in the current folder and connect it to Github.'
echo 'Please enter the project name: ("Enter" to cancel)'
read PROJECT_NAME
if [ ! -n "$PROJECT_NAME" ]; then
exit 1
fi
LOCAL_PATH=$(pwd)/$PROJECT_NAME
echo $LOCAL_PATH "Creating a project at this path. Type 'yes' if correct, any other key to cancel"
read CREATE
if [ -n "$CREATE" ]; then
if [ $CREATE == yes ]
then
# Create a private Github repository
gh repo create $PROJECT_NAME --private
# Create local project
mkdir "$LOCAL_PATH"
cd "$LOCAL_PATH"
echo "# "$PROJECT_NAME >> README.md
# Initialize Git and connect to Github
git init
git remote add github [email protected]:USERNAME/$PROJECT_NAME
git add .
git commit -m "initial commit"
git push github master
fi
fi
.sh
extension, such as create-project-with-git.sh
.sh /path/to/your/script/create-project-with-git.sh
.Example
cd /path/to/your/project/directory
sh /path/to/your/script/create-project-with-git.sh
Windows users can utilize the PowerShell script to achieve the same functionality. This script takes care of creating the project locally and connecting it with Github.
# Prompt for project name
Write-Host 'Create a project in the current folder and connect it to Github.'
Write-Host 'Please enter the project name: ("Enter" to cancel)'
$PROJECT_NAME = Read-Host
if ([string]::IsNullOrWhiteSpace($PROJECT_NAME)) {
exit
}
$LOCAL_PATH = (Get-Location).Path + "/" + $PROJECT_NAME
Write-Host $LOCAL_PATH "Creating a project at this path. Type 'yes' if correct, any other key to cancel"
$CREATE = Read-Host
if ($CREATE -eq 'yes') {
# Create a private Github repository
gh repo create $PROJECT_NAME --private
# Create local project
mkdir $LOCAL_PATH
Set-Location $LOCAL_PATH
echo "# "$PROJECT_NAME > README.md
# Initialize Git and connect to Github
git init
git remote add github [email protected]:USERNAME/$PROJECT_NAME
git add .
git commit -m "initial commit"
git push github master
}
.ps1
extension, such as create-project-with-git.ps1
.C:\path\to\your\script\create-project-with-git.ps1
.Example
cd "C:\path\to\your\project\directory"
C:\path\to\your\script\create-project-with-git.ps1
These automated scripts are more than just a convenience; they are essential tools for developers who wish to optimize their workflow and maintain uniformity across different projects. By integrating these scripts into your development process, you can focus more on coding and less on the repetitive setup tasks, thereby enhancing your overall productivity.
In conclusion, Github Cli simplifies the process of creating and managing repositories without the need to access the Github website. It helps to streamline the development workflow and offers a great way to enhance project management skills.
--public
with --private
in the repository creation command.gh repo clone <repository>
to clone a repository.CloneCoding
Innovation Starts with a Single Line of Code!