82

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@email.com

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://theirusername@bitbucket.org':

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

git pull https://bozdoz@bitbucket.org/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://bozdoz@bitbucket.org/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?

Matthias
  • 3,160
  • 2
  • 24
  • 38
bozdoz
  • 12,550
  • 7
  • 67
  • 96
  • Note: in windows, bitbucket [url/user/passwords] stored in `Credential Manager` You can check https://stackoverflow.com/questions/15381198/remove-credentials-from-git – Ahmed Nabil Oct 14 '18 at 10:48

8 Answers8

110

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>
Erik van Zijst
  • 2,282
  • 2
  • 17
  • 14
  • 2
    That's awesome. Thanks so much. Worked perfectly. New to StackOverflow? I'd like to give you some reputation if you care to have some. I can award a bounty in 2 days. – bozdoz Mar 01 '13 at 21:59
  • JFYI: a) `` doesn't exist - repo must be forked before b) push to fork doesn't change (obviously) origin – Lazy Badger Mar 01 '13 at 22:13
  • @bozdoz - must not, at least "not as expected". You have not any rights in coworker repo, – Lazy Badger Mar 02 '13 at 01:11
  • @bozdoz - BB-repo have single user, Owner. If owner isn't team – Lazy Badger Mar 02 '13 at 04:04
  • @LazyBadger Either way. Our team has been working on the same repo for months, pushing commits every night, and it has been working fine. So maybe there are a few circumstances where this method works. – bozdoz Mar 02 '13 at 05:01
  • The URL is split into your_username@bitbucket.org/owner_name/repo_name.git. It's possible that your team-member provided you with the Clone URL and you just happened to `git clone `, so every time you pushed/pulled you would have to authenticate against that user. – farthVader Apr 11 '15 at 06:44
74

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://username@bitbucket.org/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.

bozdoz
  • 12,550
  • 7
  • 67
  • 96
  • 1
    I am trying this solution, but using `git remote set-url origin` instead of `git remote add origin`. Instead of getting a prompt for username I am getting `The requested URL returned error: 401 Unauthorized while accessing` – Anthony Apr 30 '15 at 02:28
  • are you using https? @Anthony – bozdoz Apr 30 '15 at 04:59
  • Yes I am using https. `git remote set-url origin https://bitbucket.org/XXX/YYY.git` followed by `git pull` then results in `error: The requested URL returned error: 401 Unauthorized while accessing https://bitbucket.org/XXX/YYY.git/info/refs`. Putting back in the username puts everything back to normal again. – Anthony May 07 '15 at 02:07
  • @Anthony are you trying to access a team repo, or a personal repo? – bozdoz May 07 '15 at 04:02
  • it is a team repo. It was initially a personal repo but was moved to a team after being created. – Anthony May 11 '15 at 05:27
  • 1
    If you have already: git remote add origin https://username@bitbucket.org/teamName/repo.git you can change it in .git/config to – mm_ Feb 02 '16 at 18:04
  • Thanks, this solved my problem in order to push – Fernando Torres Apr 16 '21 at 02:15
  • To be overly clear, you can simply remove the the `@` and everything before it up until the closest `/` (exclusive of the `/`, natch) and you're golden, potentially. `https://creatorName@bitbucket.org/soCalledTeamName/project-name.git` changes to `https://bitbucket.org/soCalledTeamName/project-name.git` if you use `git remote set-url origin https://bitbucket.org/soCalledTeamName/project-name.git` – ruffin Jun 26 '23 at 15:54
14

The prompt:

Password for 'https://theirusername@bitbucket.org':

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://theirusername@bitbucket.org':

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 git@bitbucket.org: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
Włodzimierz Gajda
  • 1,564
  • 12
  • 11
  • I guess that I am using HTTPS and not SSH, according to your answer. Thanks for the help. @Erik's suggestion of altering the config file ultimately solved the problem. For future repos our team is going to do the bitbucket team method. – bozdoz Mar 05 '13 at 17:59
3

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
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • How would we indicate which user is pushing in a team? Do we have to set user.name each time? – bozdoz Mar 01 '13 at 23:06
  • @bozdoz - don't mix identity (used for local commit and transferred as is to BB) with authorization, which you must perform on push. You have to enter and store your credentials (BB-username and password, not Git's user.* parameters) – Lazy Badger Mar 02 '13 at 01:15
  • How do you enter and store credentials outside of git config? @lazybadger – bozdoz Mar 02 '13 at 03:40
  • @bozdoz [Permanent authentication for Git repositories over HTTP(S)] (https://confluence.atlassian.com/pages/viewpage.action?pageId=298977121) and [Is there a way to skip password typing when using https:// github](http://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using-https-github). If you use SSH things differ radically – Lazy Badger Mar 02 '13 at 04:09
3

For myself private repo, i use

git@bitbucket.org:username/blog.git

replace

https://username@bitbucket.org/username/blog.git

jadeydi
  • 99
  • 1
  • 4
3

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://otherusername@bitbucket.org/repo.git (fetch)
       https://otherusername@bitbucket.org/repo.git (push)
    
  3. updated this URL to inlcude my own user name

     git remote set-url origin https://myusername@bitbucket.org/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!

S_Jin
  • 31
  • 2
1

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

Baloneysammitch
  • 681
  • 2
  • 6
  • 11
0

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

datruq
  • 31
  • 1
  • 3