Skip to content

Instantly share code, notes, and snippets.

@AranMesquita
Last active March 18, 2023 11:14
Show Gist options
  • Save AranMesquita/6761fa8286b65895ef79763fc547f8e6 to your computer and use it in GitHub Desktop.
Save AranMesquita/6761fa8286b65895ef79763fc547f8e6 to your computer and use it in GitHub Desktop.
github_automation.ps1 is a PowerShell script to automate the process of uploading an existing project to your Github or to automate creating a new project (in your projects directory) and its respective Github repo, on your Github
"""
Make sure that Git and Github cli is installed and that you have authenticated Git to GitHub before using the github_automation.ps1 commands
Install Git:
- https://git-scm.com/downloads
Install Github cli:
- https://cli.github.com/
Run this command authenticate Git to GitHub:
- gh auth login
Installation:
- PS C:\Users\User>git clone https://gist.github.com/6761fa8286b65895ef79763fc547f8e6.git
- PS C:\Users\User>. .\github_automation.ps1
If the installation is not working visit:
- Microsofts documentation for installing script modules: https://docs.microsoft.com/en-us/powershell/scripting/learn/ps101/10-script-modules?view=powershell-7.2
"""
function github_automation() {
function existing-project($PATH_to_project_directory, $Project_Name){
gh repo create $Project_Name --public
$user_name = git config --global user.name
Set-Location $PATH_to_project_directory
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/$user_name/$Project_Name.git
git branch -M main
git push -u origin main
}
function new-project($PATH_to_project_directory, $Project_Name) {
gh repo create $Project_Name --public
$user_name = git config --global user.name
New-Item -Path $PATH_to_project_directory -Name $Project_Name -ItemType "directory"
New-Item -ItemType "file" -Path "$PATH_to_project_directory\$Project_Name\README.md"
Set-Location "$PATH_to_project_directory\$Project_Name"
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/$user_name/$Project_Name.git
git branch -M main
git push -u origin main
}
}
"""
Usage examples:
Existing Project:
- PS C:\Users\User> github_automation existing-project "C:\Users\User\desktop\Projects\github_automation_folder" "github_automation"
New Project:
- PS C:\Users\User> github_automation new-project "C:\Users\User\desktop\Projects" "github_automation"
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment