Solving "Invalid Credentials" Error When Pushing to Bitbucket
Problem Overview
If you're encountering the "fatal: Invalid credentials" error when attempting to push to Bitbucket, you're experiencing a common issue that began affecting users in early 2022. The error message typically includes:
fatal: Invalid credentials
Password for 'https://username@bitbucket.org':
remote: Bitbucket Cloud recently stopped supporting account passwords for Git authentication.
This happens because Bitbucket discontinued password-based authentication for Git operations over HTTPS starting March 1, 2022. Even if your account password is correct, it will no longer work for Git authentication.
Recommended Solutions
Method 1: Using App Passwords (Most Common)
App passwords are the recommended replacement for account passwords when authenticating with Git over HTTPS.
Step-by-Step Guide
Create an App Password
- Log in to your Bitbucket account
- Navigate to App Passwords
- Click Create app password
- Configure permissions (at minimum, select Repositories: Read and Repositories: Write)
- Give it a descriptive label (e.g., "Git Push Access")
- Copy the generated password immediately - you won't be able to view it again
Update Your Repository Configuration
For existing repositories:
git remote set-url origin https://username:app_password@bitbucket.org/username/repo-name.git
For new repositories:
git clone https://username:app_password@bitbucket.org/username/repo-name.git
WARNING
Replace username
with your Bitbucket username (not email) and app_password
with the generated app password.
Method 2: Update Credential Manager (Windows)
If you're using Windows, you can update your stored credentials:
- Open Credential Manager
- Navigate to Windows Credentials
- Find and edit your Bitbucket credentials
- Replace your password with the app password
Alternatively, add a new generic credential:
- Network address:
git:https://bitbucket.org
- Username: Your Bitbucket username
- Password: Your app password
Method 3: Configure Your IDE
If you're using an IDE like Android Studio, IntelliJ, or VS Code:
- Generate an app password as described above
- When prompted for authentication in your IDE, use:
- Username: Your Bitbucket username
- Password: The generated app password
TIP
For VS Code users with the Atlassian extension, you may be able to authenticate through the extension's authorization flow.
Method 4: Use SSH Authentication (Advanced)
For a more secure, passwordless approach, consider setting up SSH authentication:
- Generate an SSH key if you haven't already
- Add your public key to your Bitbucket account
- Change your remote URL to use SSH instead of HTTPS:
git remote set-url origin git@bitbucket.org:username/repo-name.git
INFO
SSH authentication is generally more secure and doesn't require entering credentials repeatedly once set up.
Troubleshooting Common Issues
- Username vs. Email: Ensure you're using your Bitbucket username (not email address) for authentication
- Permissions: Verify your app password has the necessary repository permissions
- Cached Credentials: Clear any cached credentials that might be using your old password
- Two-Factor Authentication: App passwords work with 2FA-enabled accounts
Why This Change Was Made
Bitbucket moved to app passwords to enhance security. App passwords:
- Provide granular control over permissions
- Can be easily revoked without changing your main account password
- Offer better security than using your primary account password across multiple services
Best Practices
- Use unique app passwords for different applications/devices
- Regularly review and revoke unused app passwords
- Consider SSH authentication for enhanced security
- Store app passwords securely using a password manager
By following these methods, you should be able to resolve the "Invalid credentials" error and continue working with your Bitbucket repositories seamlessly.
Quick Reference: App Password Creation
- Go to:
https://bitbucket.org/account/settings/app-passwords/
- Click "Create app password"
- Select required permissions (Repo Read/Write minimum)
- Copy the generated password
- Use it in place of your account password
For additional help, refer to Bitbucket's official documentation on app passwords.