Skip to content

Instantly share code, notes, and snippets.

@j3lte
Last active October 25, 2025 14:03
Show Gist options
  • Select an option

  • Save j3lte/e008c61067a8011f6b047034c6be28c1 to your computer and use it in GitHub Desktop.

Select an option

Save j3lte/e008c61067a8011f6b047034c6be28c1 to your computer and use it in GitHub Desktop.
Scripts I add to my .dotfiles

Scripts

Scripts I add to my dotfiles (Mac OS)

  • git-cleanup.sh - Used to cleanup the local mess of branches that are not on remote.
  • git-sync-fork.sh - When working with a fork, I want to sync my fork with the upstream. Instead of doing it on Github, just do it in the terminal
# Traversal
alias ..="cd .."
alias ...="cd ../../"
alias ....="cd ../../../"
alias .....="cd ../../../../"
alias ......="cd ../../../../../"
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"
# Remove dirs
alias rmD="rm -rf"
alias rmd="rm -rf"
alias cpd="cp -r"
# Tempfolder
alias createTmp="rmD tmp && mkdir tmp && cd tmp"
# Git stuff
alias git-clean-branches="~/.dotfiles/scripts/git-cleanup.sh"
alias git-sync-fork="~/.dotfiles/scripts/git-sync-fork.sh"
# Shorter Git
alias g='git'
alias gb='g b'
alias gs='g s'
alias gp='g p'
alias gpl='g pl'
alias gl='g l'
alias gll='g ll'
alias gd='g d'
alias gg='gb && g s && gl'
alias ga='g a'
# Docker stuff (from: https://davidwalsh.name/docker-remove-all-images-containers)
alias docrmc='docker rm $(docker ps -a -q)'
alias docrmi='docker rmi $(docker images -q)'
alias dockill='docker kill $(docker ps -a -q)'
# NPM
alias npmi='npm install'
alias npmig='npm install -g'
alias npmls='npm ls --depth=0'
alias npmlsg='npm ls -g --depth=0'
# PNPM
alias pnpmi='pnpm install'
alias pnpmig='pnpm install -g'
alias pnpmls='pnpm ls --depth=0'
alias pnpmlsg='pnpm ls -g --depth=0'
# Cleanup
alias cleannode="find . -name \"node_modules\" -exec rm -rf '{}' +"
alias cleands='find . -name ".DS_Store" -depth -exec rm {} \;'
newfolder() { mkdir -p "$1" && cd "$1"; }
# Cursor
alias edit='cursor .'
# Custom network things
alias download='aria2c -s 16 -j 16 -x 16'
alias fastping='ping -c 10 -i 0.1'
alias wget='wget -c'
# Outputs the sizes of folder & subfolders
alias foldersize="du -h -d 1 ./ | gsort -h"
#!/bin/bash
# Check if force mode is enabled
force_mode=false
if [ "$1" == "--force" ]; then
force_mode=true
fi
# Fetch latest updates from the remote and prune deleted branches
git fetch --prune
# Iterate over each local branch
for branch in $(git branch --format '%(refname:short)'); do
# Check if the branch is tracking a remote branch that is gone
if git branch -vv | grep -q "$branch.*: gone]"; then
if $force_mode; then
echo "Force deleting branch '$branch' as it is gone on the remote."
git branch -D "$branch"
else
# Check if the branch has unmerged changes
if git branch --merged | grep -q "$branch"; then
# Safe to delete the branch
echo "Deleting branch '$branch' as it is gone on the remote and has no unmerged changes."
git branch -d "$branch"
else
echo "Branch '$branch' is gone on the remote but has unmerged changes. Skipping."
fi
fi
fi
done
#!/bin/bash
# Git Sync Fork Script
# Syncs a forked repository with its upstream
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_error() {
echo -e "${RED}Error: $1${NC}" >&2
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}$1${NC}"
}
print_info() {
echo -e "${BLUE}$1${NC}"
}
# Check if this is a Git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
print_error "This is not a Git repository!"
exit 1
fi
print_success "✓ Git repository detected"
# Check if upstream remote exists
if ! git remote get-url upstream > /dev/null 2>&1; then
print_error "No upstream remote found!"
print_warning "Please add an upstream remote first:"
print_info " git remote add upstream <upstream-repo-url>"
exit 1
fi
print_success "✓ Upstream remote found"
# Get current branch name
current_branch=$(git branch --show-current)
print_info "Current branch: $current_branch"
# Fetch from upstream
print_info "Fetching from upstream..."
git fetch upstream
# Checkout main branch
print_info "Checking out main branch..."
if git show-ref --verify --quiet refs/heads/main; then
git checkout main
elif git show-ref --verify --quiet refs/heads/master; then
print_warning "main branch not found, using master instead"
git checkout master
else
print_error "Neither 'main' nor 'master' branch found!"
exit 1
fi
# Merge upstream into current branch
print_info "Merging upstream into current branch..."
git merge upstream/main 2>/dev/null || git merge upstream/master 2>/dev/null || {
print_error "Failed to merge upstream. Please resolve conflicts manually."
exit 1
}
print_success "✓ Successfully merged upstream changes"
# Ask if user wants to push to origin
echo
read -p "Do you want to push the changes to origin? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "Pushing to origin..."
git push origin
print_success "✓ Changes pushed to origin"
else
print_info "Skipping push to origin"
fi
print_success "Git sync completed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment