Created
January 5, 2025 15:14
-
-
Save WomB0ComB0/b1bd8f659f50279e5c29b5d4828d34e4 to your computer and use it in GitHub Desktop.
Become the owner of a repository, including the commit history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Store your new Git credentials | |
NEW_NAME="<$1>" | |
NEW_EMAIL="<$2>" | |
# Color codes for output | |
GREEN='\033[0;32m' | |
BLUE='\033[0;34m' | |
NC='\033[0m' # No Color | |
echo -e "${BLUE}Changing repository ownership...${NC}" | |
# Change the author information for all commits | |
git filter-branch --env-filter ' | |
OLD_EMAIL="[email protected]" | |
CORRECT_NAME="'"$NEW_NAME"'" | |
CORRECT_EMAIL="'"$NEW_EMAIL"'" | |
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 | |
# Force push all branches | |
git push --force --all | |
# Force push all tags | |
git push --force --tags | |
echo -e "${GREEN}Repository ownership has been updated successfully!${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment