Skip to content

Instantly share code, notes, and snippets.

View russellwpatterson's full-sized avatar
🏠
Working from home

Russell Patterson russellwpatterson

🏠
Working from home
View GitHub Profile
@russellwpatterson
russellwpatterson / flush-branches
Created April 28, 2026 18:17
Flush merged branches from local
#!/usr/bin/env bash
DEFAULT_BRANCH=`git rev-parse --abbrev-ref origin/HEAD | cut -f 2 -d /`
git branch --merged ${DEFAULT_BRANCH} | grep -v "${DEFAULT_BRANCH}\|support" | xargs git branch -d && git remote prune origin
@russellwpatterson
russellwpatterson / enum.js
Last active August 17, 2023 20:50
Basic JavaScript Enum
class Enum {
constructor(items, startAt = 0) {
if (startAt < 0) {
throw new Error("startAt must be greater than or equal to zero");
}
try {
items.forEach((item, i) => {
this[item] = i + startAt;
});
@russellwpatterson
russellwpatterson / fetch-base
Created January 7, 2022 20:34
Update the main branch from another branch, without switching. Makes rebases fun!
#!/usr/bin/env bash
if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" != "true" ]
then
echo "The current directory is not a git repository."
exit 0
fi
DEFAULT_BRANCH=$(git rev-parse --abbrev-ref origin/HEAD | cut -f 2 -d /)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
@russellwpatterson
russellwpatterson / bundle.sh
Last active June 6, 2021 04:02
Create a git bundle from every repo in a folder, using the folder name as the bundle name
mkdir -p bundles
for D in ./*; do
if [ -d "$D" ]; then
cd "$D"
FILENAME=$(basename "$(pwd)").bundle
git bundle create $FILENAME --all
mv $FILENAME ../bundles/
@russellwpatterson
russellwpatterson / replace_all_remotes.sh
Created June 5, 2021 17:10
Replace all remote URLs in a folder
OLD_USERNAME=rwpcpe
NEW_USERNAME=russellwpatterson
for D in ./*; do
if [ -d "$D" ]; then
cd "$D"
OLD_URL=$(git remote get-url origin)
NEW_URL=$(echo $OLD_URL | sed "s/$OLD_USERNAME/$NEW_USERNAME/")
if [ "$OLD_URL" != "$NEW_URL" ]; then
@russellwpatterson
russellwpatterson / replace_remote.sh
Last active June 5, 2021 17:11
Replace the username in a GitHub Remote URL
OLD_USERNAME=rwpcpe
NEW_USERNAME=russellwpatterson
OLD_URL=$(git remote get-url origin)
NEW_URL=$(echo $OLD_URL | sed "s/$OLD_USERNAME/$NEW_USERNAME/")
git remote set-url origin $NEW_URL
echo Replaced $OLD_URL with $NEW_URL