Solution: ‘Permission denied (publickey)’ for Windows

This post is mainly for Windows users who use git in the command line to push their projects on Bitbucket. I recently encountered the following error while trying to push a project into a new repository:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

This error is caused because the URL you use to access your repository depends on the SSH protocol by default. The SSH authenticates you as a user and this error basically means the URL, for some reason, can’t be verified as authentic. One solution is to switch to the HTTPS URL format found here.

bitbucketssh

Did you follow the below steps in your Command Line after creating a new repository on Bitbucket?

$cd /path/to/my/repo
$git remote add origin git@bitbucket.org:username/repositoryname.git
$git push -u origin --all # pushes up the repo and its refs for the first time
$git push -u origin --tags # pushes up any tags

Then do the following to switch to HTTPS authentication to fix the problem.
In your Terminal (Command Line), type the following:

$git rm remote origin  #removes the SSH origin URL
$git remote add origin https://accountname@bitbucket.org/accountname/reponame.git
$git push -u origin --all

That should solve it!

And by the way, this error came up because I was trying to create a webpage using Bitbucket as a web host, which you can do here. Works just like Github Pages. Love this feature!

Advertisements

Ruby | Conditionals and Flow Control

Answering Odin Project questions on Ruby Conditionals and Flow Control:

    • What is a “boolean”?
      A boolean is a binary variable that holds two possible values “true” and “false”
    • What are “truthy” values?
      Objects that are considered true in a boolean are truthy, false are considered falsey. What’s true and false varies across different languages.
    • Are nil, 0, "0", "", 1, [], {} and -1 considered true or false?
      nil -> false, 0->true, “0”->true, “”->true, 1->true, []->true, {}->true, -1->true
    • When do you use elsif?
      When you have more than two parts in an if statement.
    • When do you use unless?
      When you want to test for ‘false’.
    • What does <=> do?
      This ‘spaceship’ operator returns 1, 0, or -1 instead of 1, 0
      For example: a <=> b
      If a < b, return -1.
      If a = b, return 0.
      If a > b, return 1.2 <=> 5, returns -1 because 2 is less than 5.
    • Why might you define your own <=> method?
      When you are sorting an array. You can use it for both integers and strings. Strings are sorted according to the ASCII order and so is case sensitive. Uppercase letters come before lowercase letters.
    • What do || and && and ! do?
      || = logical ‘or’
      Evaluates the first operand. If true, returns true. Otherwise, returns the value of the second operand.

      && = logical ‘and’
      Evaluates the first operand. If false, returns false. Otherwise, returns the value of the second operand

      ! = ‘not’
      If the expression is true, returns false. If the expression is false, returns true.

    • What is returned by puts("woah") || true?
      true
    • What is ||=?
      a ||= b would mean if ‘a’ is false, then set it equal to ‘b’. Otherwise, leave it the same value before running the conditional.
    • What is the ternary operator?
      ? :
      boolean_expression ? true_expression : false_expression
      Returns the true_expression if boolean_expression is true. Otherwise, returns false_expression.
    • When should you use a case statement?
      You should use a case statement when you want to match a value to a manageable number of conditions.

||= explanation: http://ruby.zigzo.com/2013/02/01/wat-double-pipes-equals-in-ruby/
Spaceship Operator: http://www.evc-cit.info/cit020/beginning-programming/chp_07/custom_sort.html
Follow their Web Development course here: http://www.theodinproject.com/ruby-programming/advanced-ruby-building-blocks?ref=lnav