Repository access denied. access via a deployment key is read-only

前端 未结 18 2016
孤城傲影
孤城傲影 2020-11-29 15:49

After successfully cloning my repo from heroku and added another remote

1/ git clone git@heroku.com:[APP].git
2/ git remote add bitbucket ssh://git@bitbucket         


        
相关标签:
18条回答
  • 2020-11-29 15:56

    Now the SSH option is under the security settings

    Click Your Avatar --> Bitbucket Settings --> SSH Key --> Add Key

    Paste your public key

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

    All you need - add another key and use it.

    As i've found first key - always Deployment Key.

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

    you need to add your key to your profile and NOT to a specific repository. follow this: https://community.atlassian.com/t5/Bitbucket-questions/How-do-I-add-an-SSH-key-as-opposed-to-a-deployment-keys/qaq-p/413373

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

    Sometimes it doesn't work because you manually set another key for bitbucket in ~/.ssh/config.

    0 讨论(0)
  • 2020-11-29 16:04

    First choose or create the key you want to use for pushing to Bitbucket. Let's say its public key is at ~/.ssh/bitbucket.pub

    • Add your public key to Bitbucket by logging in and going to your public profile, settings, ssh-key, add key.
    • Configure ssh to use that key when communicating with Bitbucket. E.g. in Linux add to ~/.ssh/config:
        Host bitbucket.org
        IdentityFile ~/.ssh/bitbucket
    
    0 讨论(0)
  • 2020-11-29 16:07

    here is yhe full code to clone all repos from a given BitBucket team/user

    # -*- coding: utf-8 -*-
    """
    
        ~~~~~~~~~~~~
    
        Little script to clone all repos from a given BitBucket team/user.
    
        :author: https://thepythoncoding.blogspot.com/2019/06/python-script-to-clone-all-repositories.html
        :copyright: (c) 2019
    """
    
    from git import Repo
    from requests.auth import HTTPBasicAuth
    
    import argparse
    import json
    import os
    import requests
    import sys
    
    def get_repos(username, password, team):
        bitbucket_api_root = 'https://api.bitbucket.org/1.0/users/'
        raw_request = requests.get(bitbucket_api_root + team, auth=HTTPBasicAuth(username, password))
        dict_request = json.loads(raw_request.content.decode('utf-8'))
        repos = dict_request['repositories']
    
        return repos
    
    def clone_all(repos):
        i = 1
        success_clone = 0
        for repo in repos:
            name = repo['name']
            clone_path = os.path.abspath(os.path.join(full_path, name))
    
            if os.path.exists(clone_path):
                print('Skipping repo {} of {} because path {} exists'.format(i, len(repos), clone_path))
            else:
                # Folder name should be the repo's name
                print('Cloning repo {} of {}. Repo name: {}'.format(i, len(repos), name))
                try:
                    git_repo_loc = 'git@bitbucket.org:{}/{}.git'.format(team, name)
                    Repo.clone_from(git_repo_loc, clone_path)
                    print('Cloning complete for repo {}'.format(name))
                    success_clone = success_clone + 1
                except Exception as e:
                    print('Unable to clone repo {}. Reason: {} (exit code {})'.format(name, e.stderr, e.status))
            i = i + 1
    
        print('Successfully cloned {} out of {} repos'.format(success_clone, len(repos)))
    
    parser = argparse.ArgumentParser(description='clooney - clone all repos from a given BitBucket team/user')
    
    parser.add_argument('-f',
                        '--full-path',
                        dest='full_path',
                        required=False,
                        help='Full path of directory which will hold the cloned repos')
    
    parser.add_argument('-u',
                        '--username',
                        dest="username",
                        required=True,
                        help='Bitbucket username')
    
    parser.add_argument('-p',
                        '--password',
                        dest="password",
                        required=False,
                        help='Bitbucket password')
    
    parser.add_argument('-t',
                        '--team',
                        dest="team",
                        required=False,
                        help='The target team/user')
    
    parser.set_defaults(full_path='')
    parser.set_defaults(password='')
    parser.set_defaults(team='')
    
    args = parser.parse_args()
    
    username = args.username
    password = args.password
    full_path = args.full_path
    team = args.team
    
    if not team:
        team = username
    
    if __name__ == '__main__':
        try:
            print('Fetching repos...')
            repos = get_repos(username, password, team)
            print('Done: {} repos fetched'.format(len(repos)))
        except Exception as e:
            print('FATAL: Could not get repos: ({}). Terminating script.'.format(e))
            sys.exit(1)
    
        clone_all(repos)
    

    More info: https://thepythoncoding.blogspot.com/2019/06/python-script-to-clone-all-repositories.html

    0 讨论(0)
提交回复
热议问题