Skip to content

Instantly share code, notes, and snippets.

@samuelbezerrab
Created March 15, 2024 16:48
Show Gist options
  • Save samuelbezerrab/96bf258a9313e5886cf5e179779efd9f to your computer and use it in GitHub Desktop.
Save samuelbezerrab/96bf258a9313e5886cf5e179779efd9f to your computer and use it in GitHub Desktop.
Remove commit and repo metadata
#!/bin/bash
COMMIT_AUHTOR_NAME='Your name'
COMMIT_AUTHOR_EMAIL='Your e-mail'
COMMIT_DATE_TODAY=$(date '+%Y-%m-%d')" 00:00:00"
# Change commits author and date
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='$COMMIT_AUHTOR_NAME'
GIT_AUTHOR_EMAIL='$COMMIT_AUTHOR_EMAIL'
GIT_COMMITTER_NAME='$COMMIT_AUHTOR_NAME'
GIT_COMMITTER_EMAIL='$COMMIT_AUTHOR_EMAIL'
GIT_COMMITTER_DATE='$COMMIT_DATE_TODAY'
GIT_AUTHOR_DATE='$COMMIT_DATE_TODAY'
" HEAD;
# Remove all tags, as it contains past commits information
git tag | xargs git tag -d;
# Remove all remotes
git remote | xargs -n1 git remote remove
# Remove all branches, except current
git branch | grep -v $(git rev-parse --abbrev-ref HEAD) | xargs git branch -D;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment