Change Your Repo From HTTPS To The SSH Protocol

The URL you use for a repo depends on which protocol you are using, HTTPS or SSH. The Bitbucket repository Overview page has a quick way for you to see these URLS for your bb101repo repo. On the repo's Overview page look for the Clone button.

Experiment for a moment, clicking back and forth between the SSH and the HTTPS protocol links to see how the URLs differ. The table below shows the format for each DVCS based on protocol.

SSH URL format

HTTPS URL format

Mercurial ssh://hg@bitbucket.org/accountname/reponame/

https://accountname@bitbucket.org/accountname/reponame

Git

git@bitbucket.org:accountname/reponame.git

or

ssh://git@bitbucket.org/accountname/reponame.git

https://accountname@bitbucket.org/accountname/reponame.git

In the SSH format, the accountname appears after git@bitbucket.org or hg@bitbucket.org. In HTTPS format, the accountname beforegit@bitbucket.org or hg@bitbucket.org.

Make the change

Got to a terminal on your local system and navigate to your bb101repo-pratice repo. Then, do the following for Git and Mercurial:

Git users do this:

  • View your current repo configuration.
    You should see something similar to the following:
    myhost:bb101repo-practice manthony$ cat .git/config
    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
    [remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = https://newuserme@bitbucket.org/newuserme/bb101repo.git
    [branch "master"]
        remote = origin
        merge = refs/heads/master
            
    

    As you can see, the url is using the HTTPS protocol. There are a number of ways to change this value, the easiest way is just to edit the repo's configuration file.

  • Edit the ~/repos/bb101repo-pratice/.git/config file with your favorite editor.
  • Change the url value to use the SSH format for that repo.
    When you are done you should see something similar to the following:
    [remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@bitbucket.org:newuserme/bb101repo.git
            
    

Mercurial users do this:

  • View your myquotefork repo configuration.
    You should see something similar to the following:
    myhost:.hg manthony$ cat hgrc
    [paths]
    default = https://bitbucket.org/newuserme/myquotefork
            
    
  • Edit the ~/repos/myquotefork/.hg/hgrc file with your favorite editor.
  • Change the default value to use the SSH format for that repo.
    When you are done you should see something similar to the following:
    [paths]
    default = ssh://hg@bitbucket.org/newuserme/myquotefork
            
    
  • Save and close the configuration file.