I'm new to git and I think I made a mistake and I want to know if I can still fix it. I have 3 branches which are main (remote repo), development (remote repo), branchA (in local repo). I'm working on branchA and I add two commits in it and pushed it to remote repo using the code: git push origin branchA
But I noticed I committed those two commits using a wrong github account. I changed the author of the last recent commit using this code:git commit --amend --author="username <email@email.com>"
Then I did git rebase -i commithash
to be able to edit the author on my commit before my recent commit. After I've set to 'edit', I ran this command again: git commit --amend --author="username <email@email.com>"
After that, I changed something on my code and committed it again in branchA. Then I pushed it in my remote repo using git push origin branchA
and now im getting this error now:
To github.com:somename/githubrepo.git
! [rejected] branchA -> branchA (non-fast-forward)
error: failed to push some refs to 'github.com:somename/githubrepo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I understand that the hash of the commit changes if you amend something in it. But I don't understand why the error message states that my local branchA is behind remote branchA when as per my understanding my local branchA is ahead of my remote branchA. Can I fix this? Not sure if its safe to do git push force. Please help. Thank you!