Use own username/password with git and bitbucket

GitBitbucket

Git Problem Overview


I'm in a team of three; two are working locally, and I am working on the server.

My coworker set up the account, but gave me full privileges to the repository.

I set my username and email in git:

git config --global user.name "bozdoz"
git config --global user.email [email protected]

and they are identical to my username and email on bitbucket.org.

But when I pull or push to the repository it indicates their username in the prompt:

Password for 'https://[email protected]':

I was able to get a prompt for my password after trying to pull by indicating the URL with my username:

git pull https://[email protected]/path/repo.git

and it said up-to-date; and then when I pushed, it said no-fast-forward.

I read that I need to specify the branch, but I don't know how to do that in a push statement while I'm also specifying the repo URL:

git push https://[email protected]/path/repo.git

I am able to pull and push if my co-worker is around and can put his password in. But this is also listing him as the author of the push, and not me.

How can I pull and push to a repo branch as my own username?

Git Solutions


Solution 1 - Git

Run

git remote -v

and check whether your origin's URL has your co-worker's username hardcoded in there. If so, substitute it with your own:

git remote set-url origin <url-with-your-username>

Solution 2 - Git

I figured I should share my solution, since I wasn't able to find it anywhere, and only figured it out through trial and error.

I indeed was able to transfer ownership of the repository to a team on BitBucket.

Don't add the remote URL that BitBuckets suggests:

git remote add origin https://[email protected]/teamName/repo.git

Instead, add the remote URL without your username:

git remote add origin https://bitbucket.org/teamName/repo.git

This way, when you go to pull from or push to a repo, it prompts you for your username, then for your password: everyone on the team has access to it under their own credentials. This approach only works with teams on BitBucket, even though you can manage user permissions on single-owner repos.

Solution 3 - Git

The prompt:

Password for 'https://[email protected]':

suggests, that you are using https not ssh. SSH urls start with git@, for example:

git@bitbucket.org:beginninggit/alias.git

Even if you work alone, with a single repo that you own, the operation:

git push

will cause:

Password for 'https://[email protected]':

if the remote origin starts with https.

Check your remote with:

git remote -v

The remote depends on git clone. If you want to use ssh clone the repo using its ssh url, for example:

git clone [email protected]:user/repo.git

I suggest you to start with git push and git pull for your private repo.

If that works, you have two joices suggested by Lazy Badger:

  • Pull requests
  • Team work

Solution 4 - Git

Well, it's part of BitBucket philosophy and workflow:

  • Repository may have only one user: owner
  • For ordinary accounts (end-user's) collaboration expect "fork-pull request" workflow

i.e you can't (in usual case) commit into foreign repo under own credentials.

You have two possible solutions:

  1. "Classic" BB-way: fork repo (get owned by you repository), make changes, send pull request to origin repo
  2. Create "Team", add user-accounts as members of team, make Team owner of repository - it this case for this "Shared central" repository every team memeber can push under own credentials - inspect thg repository and TortoiseHg Team, owner of this repository, as samples

Solution 5 - Git

For myself private repo, i use

> [email protected]:username/blog.git

replace

> https://[email protected]/username/blog.git

Solution 6 - Git

Are you sure you aren't pushing over SSH? Maybe check the email associated with your SSH key in bitbucket if you have one.

Solution 7 - Git

I had this issue where the team member left and fetch and pull commands were still referring to his account, so I need to update that URL, I followed following steps

  1. run this command git remote -v

  2. it showed the URL that is being used for fetch and pull, like this

       https://[email protected]/repo.git (fetch)
       https://[email protected]/repo.git (push)
    
  3. updated this URL to inlcude my own user name

     git remote set-url origin https://[email protected]/repo.git/
    
  4. then I run this command to use cache as my credentials helper

     git config --global credential.helper cache
    
  5. next when I run git fetch, it asked for password, I entered password, and it got saved, next time whenever I do fetch and pull, it reads from the saved credentials.

Done!

Solution 8 - Git

I had to merge some of those good answers here! This works for me:

git remote set-url origin 'https://bitbucket.org/teamName/repo.git'

In the end, it will always prompt anyone who wants to pull from it

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbozdozView Question on Stackoverflow
Solution 1 - GitErik van ZijstView Answer on Stackoverflow
Solution 2 - GitbozdozView Answer on Stackoverflow
Solution 3 - GitWłodzimierz GajdaView Answer on Stackoverflow
Solution 4 - GitLazy BadgerView Answer on Stackoverflow
Solution 5 - GitjadeydiView Answer on Stackoverflow
Solution 6 - GitBaloneysammitchView Answer on Stackoverflow
Solution 7 - GitS_JinView Answer on Stackoverflow
Solution 8 - GitdatruqView Answer on Stackoverflow