How to Change Git Remote URL in Bitbucket and Fix Authentication Errors

Recently, I encountered an issue while trying to push changes to a Bitbucket repository after migrating to a new workspace and repository structure. The original Git remote was pointing to an outdated URL, and I needed to update it to reflect the new location. Here’s how I resolved the issue.

❌ The Problem

When trying to push to the remote, Git threw the following error:

remote: The requested repository either does not exist or you do not have access. 
fatal: unable to access 'https://bitbucket.org/old_user/old_repo.git/': 
The requested URL returned error: 403
  

This happened because the Git remote was still pointing to:

https://bitbucket.org/old_user/old_repo.git

But the correct repository is now under a new workspace:

https://new_user@bitbucket.org/new_workspace/new_repo.git

✅ The Solution

  1. Check the current Git remote:
    git remote -v
  2. Update the remote URL:
    git remote set-url origin https://new_user@bitbucket.org/new_workspace/new_repo.git
          
  3. Verify the change:
    git remote -v

    You should see the new URL listed for both fetch and push.

  4. Push your changes:
    git push origin main

    (Replace main with your actual branch name if needed.)

🔐 Authentication Tips

If you still get a 403 error, it might be due to authentication. Bitbucket now requires App Passwords for HTTPS access instead of your account password.

To create an app password:

  1. Go to Bitbucket App Passwords
  2. Generate a new password with repository:read and repository:write permissions
  3. Use your Bitbucket username and the new app password when prompted by Git

✅ Done!

With the remote updated and authentication handled correctly, Git should now push to the new repository without issues.

Tip: You can avoid entering your password every time by caching Git credentials or switching to SSH for authentication.

Comments