Git and Gitlab Please make sure you have the correct access rights and the repository exists (Solved)


Hey!

I created a Repository in GitLab.

How?

Go to https://gitlab.com

Register and Login with Valid credentials.

Go to https://gitlab.com/dashboard/projects

Click on New Project.

Create Project in GitLab

Give Proper name and Select Visibility. Click on Create.

Project in Gitlab

You will get command line instructions on Git global setup, Create a new repository, Existing folder, and Existing Git repository.

In my case, I had repository available in File System.

So I tried to follow instructions for Existing folder.

cd existing_folder
git init
git remote add origin git@gitlab.com:mitesh.soni83/petclinic-blueocean.git
git add .
git commit -m "Initial commit"
git push -u origin master

However, while Pushing the code with git push -u origin master, I faced errors.

$ git push –set-upstream 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.

Solution:

Go to Git Bash

Generate SSH Keys using following command:  ssh-keygen -t rsa -b 4096 -C “xxxxxxx.xxxxxxx@gmail.com”

It will generate Public and Private Key in a Directory.

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Mitesh/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Mitesh/.ssh/id_rsa.
Your public key has been saved in /c/Users/Mitesh/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:f3n+3r7fO9Y6DrztlKXj2cyLQbZ08pqeabHGRHcNb1I mitesh.soni83@gmail.com
The key’s randomart image is:
+—[RSA 4096]—-+
| |
| . F|
| +.|
| ..==|
| S .=.+o|
| . .++=+ |
| . BoE..|
| . &DO+|
| =YXX^|
+—-[SHA256]—–+

Go to that directory and open id_rsa.pub in Editor.

Copy the Key content.

Go to GitLab.

Go to https://gitlab.com/profile and click on SSH Keys.

Paste your public SSH key, which is usually contained in the file ‘~/.ssh/id_rsa.pub’ and begins with ‘ssh-rsa’. Don’t use your private SSH key.

Click on Add Key.

SSH Keys in Gitlab

Verify newly added key in Gitlab.

Now use git push –set-upstream origin master

$ git push -u origin master
Counting objects: 304, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (284/284), done.
Writing objects: 100% (304/304), 87.56 KiB | 0 bytes/s, done.
Total 304 (delta 80), reused 0 (delta 0)
remote: Resolving deltas: 100% (80/80), done.
To gitlab.com:xxxxxxxxx83/petclinic-blueocean1.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.

Done!

Leave a comment

Your email address will not be published. Required fields are marked *