Cannot push to Git repository on Bitbucket
Asked Answered
B

24

184

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 doing a commit, I had to add my email and name to the globals, but then it committed just fine.

When I try to use the command

git push origin master

it doesn't work. I get this message:

$ git push origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

I'm at a loss here. My friend whom I'm sharing this repository with, accessed it fine and pushed to it just fine, but I can't seem to get it to work.

Boeotian answered 18/4, 2013 at 5:0 Comment(4)
you can use https instead of gits in your remote url. e.g.: [email protected]/teamname/repository.gitMeemeece
I solved the same problem by closely following Atlassian's tutorial on how to set up SSH on your machine: confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+GitFaculty
similar issue: #12941126Echinoderm
Make sure you set the ssh key on your account, Repository settings Access keys are for read-only access (basically just pull). The read/write is when you open workspace => your profile icon => Personal Settings SSH keys ;-)Incipit
H
264

Writing this for those just getting started with Git and BitBucket on Windows & who are not as familiar with Bash (since this is both a common issue and a high ranking Google result when searching for the error message within the question).

For those who don't mind HTTPS and who are looking for a quick fix, scroll to the bottom of this answer for instructions under FOR THE LAZY

For those looking to solve the actual problem, follow the instructions below:

Fixing the SSH issue as fast as possible

This is a set of instructions derived from the URL linked to by VonC. It was modified to be as resilient and succinct as possible.

  • Don't type the $ or any lines that do not begin with $ (the $ means this is something you type into GitBash).

  • Open GitBash

Set your global info if you haven't already:

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

Check for OpenSSH:

$ ssh -v localhost
OpenSSH_4.6p1, OpenSSL...

See something like that?

  • Yes: Continue.
  • No: Skip to the FOR THE LAZY section or follow the linked article from VonC.

See if you have generated the keys already:

$ ls -a ~/.ssh/id_*

If there are two files, you can skip the next step.

$ ssh-keygen

Leave everything as the defaults, enter a passphrase. You should now see results with this command:

$ ls -a ~/.ssh/id_*

Check for an existing config file:

$ ls -a ~/.ssh/config

If you get a result, check this file for erroneous information. If no file exists, do the following:

$ echo "Host bitbucket.org" >> ~/.ssh/config
$ echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config

Confirm the contents:

$ cat ~/.ssh/config

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa
  • The single space before "IdentityFile" is required.

Check you are starting the SSH agent every time you run GitBash:

$ cat ~/.bashrc
  • If you see a function called start_agent, this step has already been completed.
  • If no file, continue.
  • If there is a file that does not contain this function, you're in a sticky situation. It's probably safe to append to it (using the instructions below) but it may not be! If unsure, make a backup of your .bashrc before following the instructions below or skip ahead to FOR THE LAZY section.

Enter the following into GitBash to create your .bashrc file:

$ echo "SSH_ENV=$HOME/.ssh/environment" >> ~/.bashrc
$ echo "" >> ~/.bashrc
$ echo "# start the ssh-agent" >> ~/.bashrc
$ echo "function start_agent {" >> ~/.bashrc
$ echo "    echo \"Initializing new SSH agent...\"" >> ~/.bashrc
$ echo "    # spawn ssh-agent" >> ~/.bashrc
$ echo "    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > \"\${SSH_ENV}\"" >> ~/.bashrc
$ echo "    echo succeeded" >> ~/.bashrc
$ echo "    chmod 600 \"\${SSH_ENV}\"" >> ~/.bashrc
$ echo "    . \"\${SSH_ENV}\" > /dev/null" >> ~/.bashrc
$ echo "    /usr/bin/ssh-add" >> ~/.bashrc
$ echo "}" >> ~/.bashrc
$ echo "" >> ~/.bashrc
$ echo "if [ -f \"\${SSH_ENV}\" ]; then" >> ~/.bashrc
$ echo "     . \"\${SSH_ENV}\" > /dev/null" >> ~/.bashrc
$ echo "     ps -ef | grep \${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {" >> ~/.bashrc
$ echo "        start_agent;" >> ~/.bashrc
$ echo "    }" >> ~/.bashrc
$ echo "else" >> ~/.bashrc
$ echo "    start_agent;" >> ~/.bashrc
$ echo "fi" >> ~/.bashrc

Verify the file was created successfully (yours should only differ where "yourusername" appears):

$ cat ~/.bashrc
SSH_ENV=/c/Users/yourusername/.ssh/environment

# start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."
    # spawn ssh-agent
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add
}

if [ -f "${SSH_ENV}" ]; then
     . "${SSH_ENV}" > /dev/null
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi
  • Close GitBash and re-open it.
  • You should be asked for your passphrase (for the SSH file you generated earlier).
  • If no prompt, you either did not set a passphrase or GitBash isn't running the .bashrc script (which would be odd so consider reviewing the contents of it!). If you are running this on a Mac(OS X), .bashrc isn't executed by default - .bash_profile is. To fix this, put this snippet in your .bash_profile: [[ -s ~/.bashrc ]] && source ~/.bashrc

If you didn't enter a passphrase, you would have seen something like this when starting GitBash:

Initializing new SSH agent...
succeeded
Identity added: /c/Users/yourusername/.ssh/id_rsa (/c/Users/yourusername/.ssh/id_rsa)

And the following should return results:

$ ssh-add -l

However, if you get the following from ssh-add -l:

Could not open a connection to your authentication agent.

It didn't spawn the SSH agent and your .bashrc is likely the cause.

If, when starting GitBash, you see this:

Initializing new SSH agent...
sh.exe": : No such file or directory

That means you forgot to escape the $ with a \ when echoing to the file (ie. the variables were expanded). Re-create your .bashrc to resolve this.

Verify the agent is running and your keys have been added:

$ ssh-add -l

Should return something similar to this:

2048 0f:37:21:af:1b:31:d5:cd:65:58:b2:68:4a:ba:a2:46 /Users/yourusername/.ssh/id_rsa (RSA)

Run the following command to get your public key:

$ cat ~/.ssh/id_rsa.pub

(it should return something starting with "ssh-rsa ......"

  • Click the GitBash window icon
  • Click Edit
  • Click Mark
  • Highlight the public key using your mouse (including the leading ssh-rsa bit and the trailing == [email protected] bit)
  • Right-click the window (performs a copy)
  • Paste your public key into Notepad.
  • Delete all the newlines such that it is only a single line.
  • Press CTRL+A then CTRL+C to copy the public key again to your clipboard.

Configure your private key with BitBucket by performing the following steps:

  • Open your browser and navigate to the BitBucket.org site
  • Login to BitBucket.org
  • Click your avatar (top-right)
  • Click Manage Account
  • Click SSH Keys (under Security on the left-hand menu)
  • Click Add Key
  • Enter Global Public Key for the Label
  • Paste the public key you copied from Notepad

A Global Public Key entry should now be visible in your list of keys.

  • Return to GitBash
  • cd into the directory containing your project
  • Change your origin to the SSH variation (it will not be if you ran the FOR THE LAZY steps)

Check your remotes:

$ git remote -v

Switch to the SSH url:

$ git remote set-url origin [email protected]:youraccount/yourproject.git

Check things are in working order:

$ git remote show origin

You should see something like this:

Warning: Permanently added the RSA host key for IP address '...' to the list of known hosts.
* remote origin
  Fetch URL: [email protected]:youruser/yourproject.git
  Push  URL: [email protected]:youruser/yourproject.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (fast-forwardable)

DONE!

You can opt to use HTTPS instead of SSH. It will require you to type your password during remote operations (it's cached temporarily after you type it once). Here is how you can configure HTTPS:

FOR THE LAZY

You should fix the SSH issue as described by VonC; however, if you're in a rush to commit and don't have the tools/time/knowledge to generate a new public key right now, set your origin to the HTTPS alternative:

> https://[email protected]/accountname/reponame.git

Using a GUI tool such as TortoiseGit or command line tools.

Here is the documentation of this alternative origin URL.

Command line to add an origin if one does not exist:

git remote add origin https://[email protected]/accountname/reponame.git

Command line to change an existing origin:

git remote set-url origin https://[email protected]/accountname/reponame.git

NOTE: your account name is not your email.

You may also want to set your global info:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Then try your push again (no need to commit again)

git push origin master
Harlie answered 18/4, 2013 at 5:0 Comment(10)
Sometime it happens that you have added everything mentioned above in ~/.bashrc but still when you run command ssh-all -l It still shows No agent In that case try this command ssh-agent /bin/bash and that will Initializing new SSH agent...Misadvise
Just curious, and this is a newb question. The SSH_ENV and the SSH_AGENT_PID is supposed to be replaced with our own info? where can we find that? I think i have a gap in information, than you.Charbonnier
@Charbonnier - Good question! The good news is no. Those are variables in bash shell scripts - they are similar to environment variables in batch files.Harlie
It's strange that in my public key, at the end it's not "[email protected]" but it's "[email protected]"Salleysalli
i get the error after this process "error: cannot open .git/FETCH_HEAD: Permission denied"Bowshot
@Bowshot was this in Linux/macOS/Windows? Check user permissions of the .git directory. Potential issue: using sudo when pulling or creating the repo. Basically your local user does not have access to the file. You would get a different error if it were a remote authorization issue.Harlie
how do I get my password to persist if i'm using another terminal like powershell?Omeromero
@Omeromero your bitbucket password? Using SSH instead is your best option. Make sure to run Start-SshAgent in your profile script and Posh-Git of course on top of msysgit (Git for Windows). But to answer your question, git config --global credential.helper wincred that will allow you to persist credentials securely.Harlie
You should use this command to generate SSH Keys: ssh-keygen -t rsa -C "[email protected]"Alphonsealphonsine
They really need to improve the UX of Git CLI. Just look at all these steps to try and use Git from a secure location. Much appreciated - but whoever can simplify these esoteric garbage processes and streamline enterprise developer setup is going to be a billionaire.Flanker
K
81

This error also occurs if you forgot adding the private key to ssh-agent. Do this with:

ssh-add ~/.ssh/id_rsa
Kearns answered 19/1, 2015 at 21:46 Comment(2)
It was the answer in my case, something I always forget when I create a new key.Lingual
it worked for me :) but you need to make sure you already have ssh private key in your local directory and public key registered in your bitbucket accountTessler
V
34

Update 2021, as commented by James:

I had to add my key to the workspace, instead of a "per-repository" basis.

Since those keys are read-only, and workspace ones allow pushing.

bitbucket.org/<my-workspace>/workspace/settings/ssh-keys 

Just be sure to remove the same keys from child repos or this won't let you add it to the workspace.

Update Q4 2022, using access keys:

https://bitbucket.org/<my-workspace>/workspace/projects/<my-project>/settings/access-keys

Original Answer (2013):

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:

https://static.mcmap.net/file/mcmap/ZG-Ab5ovK1MvaGXlXGBwaRIsXV0xKmh2XFyPLTEQamyA/_media/solved-problems/crazy-problems/bitbucket_manage_account.png

Then:

https://static.mcmap.net/file/mcmap/ZG-Ab5ovK1MvaGXlXGBwaRIsXV0xKmh2XFyPLTEQamyA/_media/solved-problems/crazy-problems/bitbucket_add_ssh.png

Images from "Integrating Mercurial/BitBucket with JetBrains software"

Velarize answered 18/4, 2013 at 5:58 Comment(10)
Just to add a bit to this. Make sure if you use BitBucket (as is shown in the screenshot) that you add the SSH key to your Account's SSH Keys (Accounts->Manage Accounts->SSH Keys). Adding it as a Deployment Key via the Repository Settings will only let that key be used for read-only operations (no committing).Dobrinsky
@Dobrinsky I agree. I have amended the answer to add more detailed pictures.Velarize
@Velarize - thanks for posting this. I have been trying in vain to get this to work on a Windows machine, and this finally did the trick. Thanks, BenBalneology
Update for 2021: I had to add my key to the workspace, instead of a "per-repository" basis. Since those keys are read only and workspace ones allow pushing. bitbucket.org/<my-workspace>/workspace/settings/ssh-keys Just be sure to remove the same keys from child repos or this won't let you add it to the workspaceCoven
@Coven Thank you for the update. i have included your comment in the answer for more visibility.Velarize
@Coven Navigating to that url just gives me "Resource not found"Tobacco
@Tobacco I confirm the URL does not seem valid anymore. I have updated the answer with what I can see now.Velarize
Yes, that exact url isn't valid because you need to replace <my-workspace> with your own workspace name.Coven
@Velarize - That url shows the message "Use access keys to gain read-only access to this repository". That is not what is desired. Your account ssh should automatically give you write access to all repos you create.Tobacco
@Tobacco True. According to James, the URL is still valid. I am confused.Velarize
H
28

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
Homecoming answered 18/11, 2016 at 5:1 Comment(3)
It works for me. I didn't remove origin, I just added a new oneEfrainefram
Thanks for the straight forward response. Worked like a charm - it was exactly what I was looking for.Doglike
This worked great, since my problem was that I renamed the repository origin via web.Resolvent
C
6

I had the same problem. My SSH keys were set correctly. I fixed this problem like this.

After creating new project in Bitbucket, use clone. Enter cloning command in terminal and it should clone empty project to your computer. After that you can copy your files to this directory and start committing and pushing to bitbucket.

Comanche answered 10/8, 2014 at 12:53 Comment(4)
How strange. I got the same problem as the OP today, but without having done a reinstall or had any system changes, my keys were fine. The git remote add process just didn't work today - I got the auth error when trying to push - but deleting .git and then using git clone & recopying my source (just a README.md) instead works fine. Thank you Rafael - I certainly wouldn't have thought to try that if not for your answer.Atmosphere
glad that this solution helped youComanche
Thanks for your answer. I was able to correct the problem by just creating a new directory and cloning in that new dir. mkdir /tmp/JUNK; cd /tmp/JUNK; git clone ...; cd ..; rm -rf JUNKFribourg
Finally. It's still working...Chouest
S
6

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>
Spiritoso answered 11/4, 2017 at 8:7 Comment(0)
A
3

Two small clarifications that might save someone the confusion I went through:

1 - Connection URLs differ for HTTPS and SSH

When connecting via https, you use

https://[email protected]/owner-account/repo-name.git

however when connecting via SSH, the account name is always "git"

ssh://[email protected]/owner-account/repo-name.git

Attempting to connect to SSH with your account name in front will lead to the error the original poster received. This is how you can do the test connecting to git@, then mistakenly try with your username and see an error.

2 - SSH Keys via team accounts will be deprecated in 2017

If you are setting up SSH keys on team accounts, they recommend switching them to personal accounts.

Abbyabbye answered 1/8, 2016 at 14:5 Comment(0)
D
2

This might not be the case for everyone but I still make an answer here in case someone is having the same cause. Basically I have two Bitbucket accounts, each have two different public keys. By running ssh -Tv bitbucket.org I managed to see that my laptop is sending incorrect key (but since both public keys are registered in bitbucket, the key is still approved, then since the key is linked to another account which does not have access to the repo I'm pushing, the push is rejected).

So I followed this guide and my issue is gone: https://blog.developer.atlassian.com/different-ssh-keys-multiple-bitbucket-accounts/

Dickenson answered 19/8, 2020 at 12:39 Comment(0)
O
1

If you are using SourceTree (I'm using 2.4.1), I found a simpler way to generate an SSH key and add it to my Bitbucket settings. This solved the problem for me.

  1. In SourceTree, go to Preferences.
  2. Go to the Accounts tab and select your account.
  3. There should be an option to generate and copy an SSH key to clipboard.
  4. Once you have copied that, go to Bitbucket in your browser. Go to [avatar] -> Bitbucket settings.
  5. Go to SSH keys.
  6. Click Add key
  7. Paste in the key you copied.

I received a confirmation email from Bitbucket that an SSH key had been added to my account.

For reference, on macOS, using Terminal, you can use the following command to see the keys generated for your device. This is where the key you generated is stored.

ls -la ~/.ssh

As others have stated, this documentation helped me: Use the SSH protocol with Bitbucket Cloud

Odelle answered 4/3, 2017 at 14:54 Comment(0)
E
1

I am using macOS and although i had setup my public key in bitbucket the next time i tried to push i got

repository access denied.

fatal: Could not read from remote repository.

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

What i had to do was Step 2. Add the key to the ssh-agent as described in Bitbucket SSH keys setup guide and especially the 3rd step:

(macOS only) So that your computer remembers your password each time it restarts, open (or create) the ~/.ssh/config file and add these lines to the file:

Host *
UseKeychain yes

Hope it helps a mac user with the same issue.

Employ answered 5/6, 2018 at 22:47 Comment(0)
H
1

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 :)

Hurter answered 1/11, 2018 at 21:6 Comment(2)
Could you please include a link to the stated Atlassian tutorial? Which are the steps to paste the key in the profile and how do I know if it is pasted in the repository?Amandaamandi
She is right here. Select the best choice for your case combination! confluence.atlassian.com/bitbucket/…Hurter
H
1

Git has changed some of its repo instructions - check that you have connected your local repo to the Git cloud - check each of these steps to see if you have missed any.

Git documentation[https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/connecting-to-github-with-ssh] if you prefer following documentation - it is far more detailed and worth reading to understand why the steps below have been summarised.

My Git Checklist:-

  1. The master branch has changed to main
  2. If you have initialised your repo and want to start from scratch, un-track git with $rm -rf .git which recursively removes git
  3. Check you're not using "Apple Git". Type which git it should say /usr/local/bin/git - if you are install git with Homebrew $brew install git
  4. Configure your name and email address for commits (be sure to use the email address you have registered with Github):
$git config --global user.name "Your Name"
$git config --global user.email "[email protected]"
  • Configure git to track case changes in file names:
$git config --global core.ignorecase false

If you have made a mistake you can update the file $ls -a to locate file then $open .gitignore and edit it, save and close.

  1. Link your local to the repo with an SSH key. SSH keys are a way to identify trusted computers, without involving passwords.
    Steps to generate a new key
  • Generate a new SSH key by typing ssh-keygen -t rsa -C "[email protected]" SAVE THE KEY
  • You'll be prompted for a file to save the key, and a passphrase. Press enter for both steps leaving both options blank (default name, and no passphrase).
  • Add your new key to the ssh-agent: ssh-add ~/.ssh/id_rsa
  • Add your SSH key to GitHub by logging into Github, visiting Account settings and clicking SSH keys. Click Add SSH key

You can also find it by clicking your profile image and the edit key under it in the left nav.

  • Copy your key to the clipboard with the terminal command: pbcopy < ~/.ssh/id_rsa.pub

  • In the Title field put something that identifies your machine, like YOUR_NAME's MacBook Air

  • In the Key field just hit cmd + V to paste the key that you created earlier - do not add or remove and characters or whitespace to the key

  • Click Add key and check everything works in the terminal by typing: ssh -T [email protected]

    You should see the following message:

    Hi YOUR_NAME! You've successfully authenticated, but GitHub does not provide shell access.
    

Now that your local machine is connected to the cloud you can create a repo online or on your local machine. Git has changed the name master for a branch main. When linking repos it is easier to use the HTTPS key rather than the SSH key. While you need the SSH to link the repos initially to avoid the error in the question.

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

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

Follow the steps you now get on your repo - GitHub has added an additional step to create a branch (time of writing Oct 2020).

  • to create a new repository on the command line echo "# testing-with-jest" >> README.md git init git add README.md git commit -m "first commit" git branch -M main git remote add origin — (use HTTPS url not SSH) git push -u origin main

  • to push an existing repository from the command line git remote add origin (use HTTPS url not SSH) git branch -M main git push -u origin main

If you get it wrong you can always start all over by removing the initialisation from the git folder in your local machine $rm -rf .git and start afresh - but it is useful to check first that none of the steps above are missed and always the best source of truth is the documentation - even if it takes longer to read and understand!

Hedda answered 6/10, 2020 at 10:35 Comment(0)
R
0

I got this very same error for one repository - suddenly, all other ones were and still work fine when I'm trying to push commits. The problem appeared to be with the SSH key (as you already know from the previous comments) - on bitbucket go to View Profile then click Manage Account.

On the left hand side click on the SSH Keys then add the one that you have on your system under ~/.ssh/ directory.

If you don't have one generated yet - use the instructions from one of the posts, but make sure that you either use the default id_dsa.pub file or custom named one, with later requiring the -i option with the path to the key when you connect i.e.

ssh -i ~/.ssh/customkeyname username@ip_address

Once you've added your local key to your account at bitbucket, you'll be able to start interacting with your repository.

Randolphrandom answered 10/8, 2015 at 18:37 Comment(0)
B
0

I found the solution that worked best for me was breaking up the push into smaller chunks.

and removing the large screenshot image files (10mb+) from the commits

Security wasnt an issue in the end more about limits of bin files

Bemis answered 30/1, 2017 at 8:5 Comment(2)
You get the error above, noted by the OP, and it wasn't an auth/security issue? It was the size of your commit?Danieldaniela
That's what happenedBemis
C
0

This error also shows up when the repository does not exist. I tried all the answers until I saw the repo name was missing a dash

Choppy answered 11/5, 2017 at 9:29 Comment(0)
V
0

For errors:

[error] repository access denied. access via a deployment key is read-only. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

[error] fatal: Could not read from remote repository.

[error] fatal: Unable to find remote helper for 'https'

I solved following this steps:

First install this dependencies:

$ yum install expat expat-devel openssl openssl-devel

Then remove git:

$ yum remove git git-all

Now Build and install Git on last version, in this case:

$ wget https://github.com/git/git/archive/v2.13.0.tar.gz
$ tar zxf v.2.13.0.tar.gz
$ cd git-2.13.0/

Then for the configure:

$ make configure
$ ./configure --with-expat --with-openssl

And finally install like this:

$ make 
$ make install install-doc install-html install-info

that´s it, now configure your repo with https:

$ git remote add origin https://github.com/*user*/*repo*.git
# Verify new remote
$ git remote -v

if you have configured an ssh key in your remote server you have to delete it.

Vanbuskirk answered 17/5, 2017 at 14:5 Comment(0)
G
0

I got this error

Connection to bitbucket.org closed by remote host. fatal: Could not read from remote repository. Please make sure you have the correct access rights.

Then i tried

git config --global user.email "[email protected]"

worked without quotes.

Genaro answered 9/12, 2017 at 19:20 Comment(0)
T
0

I found the git command line didnt fancy my pageant generated keys (Windows 10).

See my answer on Serverfault

Tyrolienne answered 11/12, 2017 at 14:58 Comment(0)
R
0

This is probably caused by having multiple SSH keys in SSH agent (and/or BitBucket). Check Atlassian documentation for the workaround for this

Richelieu answered 13/6, 2019 at 16:18 Comment(0)
I
0

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/

Ithnan answered 18/3, 2020 at 0:51 Comment(0)
T
0

Navigate to your source project, open the .git folder, open the config file with notepad++ (or any other text editor) and compare the two .git URL on this file with the .git URL on your source .git.

This has solved my problem.

Trilingual answered 9/8, 2022 at 16:49 Comment(0)
B
0

I faced the same error and it was because of SSH key. So I changed the clone option from SSH to Https and cloned the repository again. If you want to do push changes on existing code which was cloned by SSH option but now not able to push it then change that code base to https using following steps in eclipse/STS: 1] Right click on project -> team -> show in repositories view 2]In git repositories section in eclipse, select the project 3]Remotes -> origin -> right click on origin -> configure push -> click on change option 4]change the SSH URI to Https URI of repository and click finish.

Brainwashing answered 6/11, 2023 at 10:54 Comment(0)
F
-1

Just try

git remote add origin <HTTP URL>
Frankel answered 19/8, 2019 at 8:53 Comment(2)
we don't like typing username/password everytime we fetch/push into bitbucket/github/etc/Ithnan
In that case, you can use the ssh one URL. You just have to add your public SSH key in your git repo.Frankel
M
-1

This worked for me

git ls-remote --tags --heads git@your_repository

It wanted to add to the list of known hosts and it couldn't as with only yarn install command.

Mercurialize answered 7/8, 2023 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.