Skip to content

Instantly share code, notes, and snippets.

@apolopena
Last active April 23, 2021 15:47
Show Gist options
  • Save apolopena/2d6bff6ee9609e1e42d4bb1dac4fc434 to your computer and use it in GitHub Desktop.
Save apolopena/2d6bff6ee9609e1e42d4bb1dac4fc434 to your computer and use it in GitHub Desktop.
Sets up local and remote github repositories using `gitpod-laravel-starter` as the starting point.
#!/bin/bash
#
# SPDX-License-Identifier: MIT
# Copyright © 2021 Apolo Pena
#
# new-lgs.sh
# Description:
# Sets up a new project repository locally and remotely using gitpod-laravel-starter as the starting point.
# For use in your .bashrc, .bash_profile etc.. You may copy the functions and leave out the licensing.
# Functions from this script can also be called directly using your bash interpreter:
# bash new-lgs.sh new_lgs myreponame myusername
# or
# bash new-lgs.sh new_lgs_from_branch myreponame mybranchname myusername
#
# Additional Notes:
# Make sure the project name you use matches an empty repository you have created on github. If you are
# creating a project from a branch, make sure that branch exists
# Also make sure you are in the location where you want your project to be before you run this script
new_lgs() {
local new_repo_project_name="$1"
local github_username="$2"
mkdir "$new_repo_project_name" &&
cd "$new_repo_project_name" &&
git clone https://github.com/apolopena/gitpod-laravel8-starter.git . &&
rm -rf .git &&
git init &&
git add -A &&
git commit -m "initial commit built from https://github.com/apolopena/gitpod-laravel8-starter" &&
git remote add origin "https://github.com/$github_username/$new_repo_project_name.git" &&
git branch -m main &&
git push -u origin main
}
new_lgs_from_branch() {
local branch="$1"
local new_repo_project_name="$2"
local github_username="$3"
mkdir "$new_repo_project_name" &&
cd "$new_repo_project_name" &&
git clone https://github.com/apolopena/gitpod-laravel8-starter.git -b "$branch" --single-branch . &&
rm -rf .git &&
git init &&
git add -A &&
git commit -m "initial commit built from the $branch branch of https://github.com/apolopena/gitpod-laravel8-starter" &&
git remote add origin "https://github.com/$github_username/$new_repo_project_name.git" &&
git branch -m main &&
git push -u origin main
}
# Call functions from this script gracefully
if declare -f "$1" > /dev/null
then
# call arguments verbatim
"$@"
else
echo "helpers.sh: '$1' is not a known function name." >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment