Giter Club home page Giter Club logo

anon-repo-convert's Introduction

Anonymous Repository Convert

Convert an existing repository to an anonymous repository with new user, email, and merge messages.

Problem

You may find you have some code you would like to share publicly.

The code exists on a profile you do not want to expose publicly.

The user, email, and merge commit messages show the information of the existing public profile.

We have:

Author: Real Guy <[email protected]>
Merge branch 'master' of github.com:Real-Guy/SuperRadCode

We need:

Author: Anonymous <[email protected]>
Merge branch 'master' of github.com:Anonymous/SuperRadCode

Solution

I would recomend having a backup of the infomation ready.

If you make a mistake you can easily start over.

Convert

Make a local clone of the existing reposity.

Then run:

git filter-branch -f --env-filter '
WRONG_EMAIL="[email protected]>"
NEW_NAME="Anonymous"
NEW_EMAIL="[email protected]"

if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$NEW_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$NEW_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

You will most likely need to run multiple commands, so we will add the force (-f) flag.

You will want to run git log to make sure there are not other committers like "[email protected]".

Once all your commits have the proper user/email we may still have merges that show the old reposity URL.

Run as much as needed:

git filter-branch --msg-filter '
sed "s/github.com:Real-Guy/github.com:Anonymous/g"
' --tag-name-filter cat -- --branches --tags

This is a very simple sed command that can be used other ways for commit messages.

Simply use the same format:

git filter-branch --msg-filter '
sed "s/<old infomation>/<new infomation>/g"
' --tag-name-filter cat -- --branches --tags

Push

By now, you should have all the old information removed.

Change the remote info, switch to default branch and force push to the new repository:

git remote rm origin
git remote add origin [email protected]:Anonymous/SuperRadCode.git

Switch to new default branch, and force push to new reposity:

git branch -M main
git push -f --set-upstream origin main

This will produce an exact replica of the commit history under another account.

This will work even if the code pre-dates the account creation date.

Warning

Github only allows an SSH key to be used on a single account.

If you are using the same machine, you may need to remove the key.

The site will allow you to add/remove keys to facilitate this without limit.

anon-repo-convert's People

Contributors

buckaroo-0-2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.