gitgithubgit-filter-branch

Why changed history (by filter-branch) get reverted when using fetch


I am using Github and trying to change the committer, author and email of old commits for a user, I used .sh file to change the history:

#!/bin/sh

git filter-branch -f --env-filter 'if [ "$GIT_AUTHOR_NAME" = "<Old_Name>" ]; then
GIT_AUTHOR_EMAIL=<New_Email>;
GIT_AUTHOR_NAME="<New_Name>"
GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL;
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all

After executing the file I push all the changes with:

git push --all origin --force

For a moment of time it appears that it worked, but once I fetch, only the local branches stay as updated while the origin branches reset to old names

Can someone help me to solve this issue?


Solution

  • I find a way by getting a local branch for all the branches before executing the update .sh file:

    #!/bin/bash
    for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
        git branch --track "${branch##*/}" "$branch"
    done
    

    please note this will create a local branch for all origin branches except master