How to solve errors on git remote repository access
Sometime, we encounter error to pull or push repository from github, gitlab or company’s remote git space. I like to keep note about how I do resolve it for my future work.
git status
1
2
3
4
5
|
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
|
- If
git status
says there are anything unstaged or not committed in local repository, do git add <file path>
and git commit -m <commit message>
.
1
2
|
$ ssh -T git@gitlab.com
Welcome to GitLab, @hoge!
|
- If
ssh -T
returns Permission denied (publickey).
,
- check
~/.ssh/config
and whether the right ssh-key is configured for the remote URL domain. For example,
1
2
3
4
5
6
|
$ vim ~/.ssh/config
Host gitlab
Hostname gitlab.com
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa4
|
-
In the above case, If the public key of id_rsa4
(the file name should be id_rsa4.pub
) is not registerred to github/gitlab,
- Register it at github/gitlab > settings > SSH key, register that public key.
-
If local ssh file configuration is right and remote public key was registered, but you cannot access to remote, you should check git remote -v
below.
Check .git/config (Add 2021.05.11)
Check .git/config
and check remote origin url.
If url has https address, this repository directs to remote orgin url over https.
1
2
|
[remote "origin"]
url = https://github.com/tatoflam/canvas-lms.git
|
Sometime, you can fix some error prevention by specifying remote origin url over ssh.
1
2
|
[remote "origin"]
url = git@github.com:tatoflam/canvas-lms.git
|
git remote -v
1
2
3
|
$ git remote -v
origin git@github.com:mraardvark/pyupdi.git (fetch)
origin git@github.com:mraardvark/pyupdi.git (push)
|
- If above command returns error or different URL, You might need to add remote repository,
1
|
$ git remote add origin git@github.com:mraardvark/pyupdi.git
|
- Or change remote repository URL.
1
|
$ git remote set-url origin git@github.com:mraardvark/pyupdi.git
|
- If
git remote -v
returns the url address beginning from “https” like origin https://gitlab.fabcloud.org/academany/...
, your remote url setting is to set by HTTPS. HTTPS sometime requires local client credential and it may brings error.
Add ssh key to ssh-key agent.
Sometime, you need to add ssh key locally to ssh-agent by ssh-add
.
1
2
|
$ ssh-add -l
Could not open a connection to your authentication agent.
|
1
2
|
$ ssh-add -l
4096 2048 SHA256:EABF+xxxxxxxxxNe9S62gJhAyf8d/xxxxxxxxxxFSuY user@mycomputer (RSA)
|
1
2
|
ssh-add ~/.ssh/rsa_gitlab
Identity added: /c/Users/hoge/.ssh/id_rsa4 (hoge@gmail.com)
|
1
2
|
$ ssh -T git@gitlab.com
Welcome to GitLab, @hoge!
|
References