I just added additional remote A to my repo B and then run git fetch A. How can I undo the fetch? If I just remove remote A
You can delete whatever branches you accidentally fetched that you don't want to keep with the following command:
git update-ref -d refs/remotes/YOUR_REMOTE_NAME/BRANCH_NAME_TO_DELETE
To prevent them from getting fetched again, set your git remote to only fetch specified branches: git remote set-branches YOUR_REMOTE_NAME desired_branch1 [desired_branch2, desired_branch3, etc], e.g. git remote set-branches origin master.
The default behaviour of set-branches is to always replace the list. If you want to append, use the --add option: git remote set-branches --add origin another_branch