Please don't ask why, but I have 2 GitHub accounts. I'll call these two accounts GH1 and GH2.
The repository : The repository is private, it is in an organization, and the only members of the organization are GH1 and GH2. It is a repository that I don't want linked to my main, GH1, which is why I want there to be no trace of GH1 on that repository, and why I am only pushing to it as GH2.
The repository is being used by me to test workflows, before I deploy them to one of the public repositories of the organization.
When I push to the repo locally (as in, git push
), my commit is attributed to GH2, but when I check the workflow runs, it says that it was pushed by GH1. How can I make sure that the commit is always attributed to GH2?
To clarify : The commit is attributed to GH2, the incorrect attribution to GH1 is in the GitHub Actions workflow runs.
(It has been modified with inspect element to redact sensitive information.)
There are two past solutions on Stack Overflow for fixing your situation.
(Which is part of this question: How to amend several commits in Git to change author )
Part 1:
Set your git author settings. Eg:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
Then reset the author for all commits after the given SHA
git rebase -i YOUR_SHA -x "git commit --amend --reset-author -CHEAD"
This will pop up your editor to confirm the changes. All you need to do here is save and quit and it will go through each commit and run the command specified in the -x flag.
You can also change the author while maintaining the original timestamps with:
git rebase -i YOUR_SHA -x "git commit --amend --author 'New Name <new_address@example.com>' -CHEAD"
Part 2:
git filter-branch --env-filter 'if [ "$GIT_AUTHOR_EMAIL" = "incorrect@email" ]; then
GIT_AUTHOR_EMAIL=correct@email;
GIT_AUTHOR_NAME="Correct Name";
GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL;
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all
I would read the details from the links to make sure you understand what you're doing before executing the actions.
Git: fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists
Try pushing with SSH instead. I'd create 2 keys for GH1 and GH2, and then edit my SSH config to something like this:
Host github.com-GH2
HostName github.com
User GH2
IdentityFile ~/.ssh/github_GH2
and in the repositories where I want to be attributed as GH2, I can simply run this git command:
git remote set-url origin git@github.com-GH2:user/repo.git
I did a push with that SSH url set, and I'm proud to say that the GitHub Actions workflow runs no longer attributes the commit to GH1 (see below screenshot).
I found a git identity manager. Hopefully I can use this to change between GH1 and GH2, but I haven't tried it yet for GitHub Actions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.