Cannot push to Git repository on Bitbucket

后端 未结 21 664
春和景丽
春和景丽 2020-11-29 14:40

I created a new repository and I\'m running into a strange error. I\'ve used Git before on Bitbucket but I just reformatted and now I can\'t seem to get Git to work. After

相关标签:
21条回答
  • 2020-11-29 15:30

    I had this issue and I thought I was crazy. I have been using SSH for 20 years. and git over SSH since 2012... but why couldn't I fetch my bitbucket repository on my home computer?

    well, I have two bitbucket accounts and had 4 SSH keys loaded inside my agent. even if my .ssh/config was configured to use the right key. when ssh was initializing the connection, it was using them in order loaded into the agent. so I was getting logged into my personal bitbucket account.

    then getting a Forbidden error trying to fetch the repo. makes sense.

    I unloaded the key from the agent

    ssh-add -d ~/.ssh/personal_rsa

    then I could fetch the repos.

    ... Later I found out I can force it to use the specified identity only

     Host bitbucket.org-user2
         HostName bitbucket.org
         User git
         IdentityFile ~/.ssh/user2
         IdentitiesOnly yes
    

    I didn't know about that last option IdentitiesOnly

    from the bitbucket documentation itself

    https://blog.developer.atlassian.com/different-ssh-keys-multiple-bitbucket-accounts/

    0 讨论(0)
  • 2020-11-29 15:32

    Just try

    git remote add origin <HTTP URL>
    
    0 讨论(0)
  • 2020-11-29 15:33

    Reformatted means you probably deleted your public and private ssh keys (in ~/.ssh).

    You need to regenerate them and publish your public ssh key on your BitBucket profile, as documented in "Use the SSH protocol with Bitbucket", following "Set up SSH for Git with GitBash".

    Accounts->Manage Accounts->SSH Keys:

    http://solvedproblems.hydex11.net/_media/solved-problems/crazy-problems/bitbucket_manage_account.png

    Then:

    http://solvedproblems.hydex11.net/_media/solved-problems/crazy-problems/bitbucket_add_ssh.png

    Images from "Integrating Mercurial/BitBucket with JetBrains software"

    0 讨论(0)
  • 2020-11-29 15:33

    Get the ssh done as in the Atlassian tutorial and make sure the private key is being pasted in the profile, not in the repository :)

    0 讨论(0)
  • 2020-11-29 15:35

    I solved this by removing the remote using command:

    git remote remove origin
    

    and then tried to add remote using https url instead of ssh

    git remote add origin httpsUrl
    

    It asks for github credentials. Enter credentials and then try pushing to git using:

    git push origin master
    
    0 讨论(0)
  • 2020-11-29 15:36

    Just need config file under ~/.ssh directory
    ref : https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html
    add bellow configuration in config file

    Host bitbucket.org
     IdentityFile ~/.ssh/<privatekeyfile>
    
    0 讨论(0)
提交回复
热议问题