Skip to content

Instantly share code, notes, and snippets.

@matthiasseghers
Last active September 4, 2023 12:50
Show Gist options
  • Save matthiasseghers/688e55bdeeac22e8a335ab09aaa47fed to your computer and use it in GitHub Desktop.
Save matthiasseghers/688e55bdeeac22e8a335ab09aaa47fed to your computer and use it in GitHub Desktop.
Git scripts
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="NewUsername"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
#!/bin/bash
# Define the default branch (e.g., 'main' or 'master')
default_branch="main"
# Define the stale branch age threshold in days
stale_age_days=90
# List all branches except the default branch
for branch in $(git branch -r --no-merged $default_branch | grep -vE "origin/$default_branch"); do
# Get the last commit date for the branch
last_commit_date=$(git log -n 1 --format="%cd" --date=relative $branch)
# Check if the branch is older than the stale age threshold
if [[ "$last_commit_date" == *months* || "$last_commit_date" == *years* ]]; then
# Branch is considered stale
echo "Stale branch: $branch (last commit: $last_commit_date)"
# Check if the branch is associated with a closed issue or pull request
associated_issues=$(hub issue --format='%I %s' -a "$branch" -s closed)
if [[ -n "$associated_issues" ]]; then
echo "Associated closed issues/PRs:"
echo "$associated_issues"
fi
# Optionally, delete the branch if you're sure it's safe to do so
# git push origin --delete $branch
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment