在 git 和 bitbucket 中使用自己的用户名/密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15166722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use own username/password with git and bitbucket
提问by bozdoz
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 中设置了我的用户名和电子邮件:
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.
它们与我在 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:
通过使用我的用户名指示 URL,我能够在尝试拉取密码后获得密码提示:
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:
我读到我需要指定分支,但我不知道如何在 push 语句中执行此操作,同时还指定了 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?
如何以我自己的用户名拉取并推送到 repo 分支?
回答by Erik van Zijst
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:
并检查您的源 URL 中是否硬编码了您同事的用户名。如果是这样,请将其替换为您自己的:
git remote set-url origin <url-with-your-username>
回答by bozdoz
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.
我确实能够将存储库的所有权转让给BitBucket上的团队。
Don'tadd the remote URL that BitBuckets suggests:
不要添加 BitBuckets 建议的远程 URL:
git remote add origin https://[email protected]/teamName/repo.git
Instead, add the remote URL without your username:
相反,添加没有您的用户名的远程 URL:
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.
这样,当您从仓库拉取或推送到仓库时,它会提示您输入用户名,然后输入密码:团队中的每个人都可以根据自己的凭据访问它。这种方法仅适用于 BitBucket 上的团队,即使您可以管理单一所有者存储库的用户权限。
回答by W?odzimierz Gajda
The prompt:
提示:
Password for 'https://[email protected]':
suggests, that you are using https not ssh. SSH urls start with git@, for example:
建议您使用 https 而不是 ssh。SSH url 以 git@ 开头,例如:
[email protected]: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
.
如果远程源以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
. 如果要使用 ssh 克隆 repo,请使用其 ssh url,例如:
git clone [email protected]:user/repo.git
I suggest you to start with git push
and git pull
for your private repo.
我建议你开始git push
和git pull
你的私人回购协议。
If that works, you have two joices suggested by Lazy Badger:
如果可行,您有 Lazy Badger 建议的两种乐趣:
- Pull requests
- Team work
- 拉取请求
- 团队合作
回答by Lazy Badger
Well, it's part of BitBucket philosophy and workflow:
嗯,这是 BitBucket 理念和工作流程的一部分:
- Repository may have only one user: owner
- For ordinary accounts (end-user's) collaboration expect "fork-pull request" workflow
- 存储库可能只有一个用户:所有者
- 对于普通帐户(最终用户的)协作期望“fork-pull request”工作流程
i.e you can't (in usual case) commit into foreign repo under own credentials.
即您不能(在通常情况下)根据自己的凭据提交外国回购。
You have two possible solutions:
您有两种可能的解决方案:
- "Classic" BB-way: fork repo (get owned by yourepository), make changes, send pull request to origin repo
- 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 thgrepository and TortoiseHg Team, owner of this repository, as samples
- “经典”BB 方式:fork repo(由您的存储库拥有),进行更改,将拉取请求发送到原始存储库
- 创建“团队”,将用户帐户添加为团队成员,使团队成为存储库的所有者 - 对于这个“共享中央”存储库,每个团队成员都可以根据自己的凭据推送 - 检查thg存储库和TortoiseHg 团队,此存储库的所有者, 作为样本
回答by Baloneysammitch
Are you sure you aren't pushing over SSH? Maybe check the email associated with your SSH key in bitbucket if you have one.
你确定你不是在推动 SSH?如果你有的话,可以在 bitbucket 中检查与你的 SSH 密钥相关联的电子邮件。
回答by jadeydi
For myself private repo, i use
对于我自己的私人回购,我使用
[email protected]:username/blog.git
[email protected]:用户名/blog.git
replace
代替