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
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.
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 "you@example.com"
Check for OpenSSH:
$ ssh -v localhost
OpenSSH_4.6p1, OpenSSL...
See something like that?
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
Check you are starting the SSH agent every time you run GitBash:
$ cat ~/.bashrc
start_agent
, this step has already been completed.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
.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 ......"
ssh-rsa
bit and the trailing == youremail@yourdomain.com
bit)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:
Global Public Key
for the LabelA Global Public Key
entry should now be visible in your list of keys.
Check your remotes:
$ git remote -v
Switch to the SSH url:
$ git remote set-url origin git@bitbucket.org: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: git@bitbucket.org:youruser/yourproject.git
Push URL: git@bitbucket.org: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://accountname@bitbucket.org/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://accountname@bitbucket.org/accountname/reponame.git
Command line to change an existing origin:
git remote set-url origin https://accountname@bitbucket.org/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 "you@example.com"
Then try your push again (no need to commit again)
git push origin master
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.
This error also occurs if you forgot adding the private key to ssh-agent. Do this with:
ssh-add ~/.ssh/id_rsa
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
Two small clarifications that might save someone the confusion I went through:
When connecting via https, you use
https://your_account_name@bitbucket.org/owner-account/repo-name.git
however when connecting via SSH, the account name is always "git"
ssh://git@bitbucket.org/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.
If you are setting up SSH keys on team accounts, they recommend switching them to personal accounts. A useful tip to avoid e