1

I am using Git on Windows 10 via git bash. I have a couple of projects locally that I want to push to different GitHub repositories.

This is my gitconfig -

[user]
    name = my-name
    email = my-email@gmail.com
[remote "origin"]
    url = git@github.com:my-name/terraform_lambda_implementation.git
    proxy = http://proxy.XXXXX.net:port
[http]
    sslBackend = openssl
    sslCAInfo = " C:\\Users\\username\\Downloads\\proxy.pem"
    sslverify = false
[core]
    editor = notepad++.exe -multiInst -nosession
[merge]
    tool = p4merge
[mergetool "p4merge"]
    path = C:/Program Files/Perforce/p4merge.exe
[mergetool]
    prompt = false
[diff]
    tool = p4merge
[difftool "p4merge"]
    path = C:/Program Files/Perforce/p4merge.exe
[difftool]
    prompt = false
[alias]
    hist = log --all --graph --decorate --oneline
[remote "ml"]
    url = git@github.com:my-name/data_science_ML.git

[remote "testpush"]
    url = git@github.com:my-name/test_push.git

I have a proxy because I am behind a corporate firewall. I am using PyCharm for my local development. I have added my github account to the PyCharm version control.

I have created separate SSH keys fro each project and I have added them as deploy keys with write access in the respective github repos.

When I try to push from my local -

git push ml master

I get the below error -

ERROR: Permission to my-name/data_science_ML.git denied to deploy key
fatal: Could not read from remote repository.

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

I get the same issue when I try to push the other project.

When I run git remote show origin from the respective projects I get this -

from origin project -

* remote origin
  Fetch URL: git@github.com:my-name/terraform_lambda_implementation.git
  Push  URL: git@github.com:my-name/terraform_lambda_implementation.git
  Push  URL: git@github.com:my-name/terraform_lambda_implementation.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)


from ml project -

* remote origin
  Fetch URL: git@github.com:my-name/terraform_lambda_implementation.git
  Push  URL: git@github.com:my-name/terraform_lambda_implementation.git
  Push  URL: git@github.com:my-name/data_science_ML.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)

from testpush project -

* remote origin
  Fetch URL: git@github.com:my-name/terraform_lambda_implementation.git
  Push  URL: git@github.com:my-name/terraform_lambda_implementation.git
  Push  URL: git@github.com:my-name/test_push.git
  HEAD branch: master
  Remote branch:
    master new (next fetch will store in remotes/origin)
  Local ref configured for 'git push':
    master pushes to master (local out of date)

I have added the SSH keys in the ~/.ssh/config -

# ~/.ssh/config

Host  git@github.com:my-name/terraform_lambda_implementation.git
HostName github
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes

Host git@github.com:my-name/data_science_ML.git
HostName github
User git
IdentityFile ~/.ssh/ds_rsa
IdentitiesOnly yes

Host git@github.com:my-name/test_push.git
HostName github
User git
IdentityFile ~/.ssh/test_push_rsa
IdentitiesOnly yes

What am I doing wrong?

Seeker90
  • 785
  • 4
  • 17
  • 37
  • When you push to `git@github.com:…` git starts ssh to `git@github.com` — and how the poor ssh should distinguish which key is for what account? You need to help ssh to know your keys. – phd Feb 26 '20 at 15:53
  • https://stackoverflow.com/search?q=%5Bgithub%5D+multiple+accounts – phd Feb 26 '20 at 15:53
  • @phd _ I have added the ssh config file in the question. I have specified the keys there. Please have a look. I am still facing the same issue. – Seeker90 Feb 26 '20 at 16:00
  • You have 2 remotes, one with URL `git@github.com` and another with URL `git@github.com`. How could `ssh` distinguish them? No way. You have to change URLs for your remotes to use your host names: `terraform_lambda_implementation.github.com` and `data_science_ML.github.com`; `git remote set-url origin git@terraform_lambda_implementation.github.com:my-name/terraform_lambda_implementation.git` and so on for all remotes. – phd Feb 26 '20 at 16:07
  • @phd - I am sorry. I am not sure if I understood you. I have changed the Host in ssh config. Is that what you implied ? – Seeker90 Feb 26 '20 at 16:26
  • No, you need to change URLs in `.git/config` so that git pass different host names to ssh. I already shown a command to do that: `git remote set-url …` – phd Feb 26 '20 at 16:27
  • @phd . I changed the URLs in the .git/config as you mentioned. Now when I try to push I get ERROR: repository not found. – Seeker90 Feb 26 '20 at 16:38
  • Wrong hosts in `~/.ssh/config` — they must be hosts, not git URLs. SSH knows nothing about git URLs. Also please [edit] the question and show your new URLs. – phd Feb 26 '20 at 16:45
  • @phd - I am able to push the individual projects to their respective git repos. But I refer one repo as origin and the rest by different names as specified in the gitconfig. Ideally what I would like to have is - while working on every project locally, the project should be addressed as 'origin'. So when I try to push the individual projects from local I just do - git push origin master. Is that possible? – Seeker90 Feb 28 '20 at 09:30
  • In one repository? No, one `.git/config` can have only one remote named `origin`. In many different repositories — just name the default remote in every repository `origin`. – phd Feb 28 '20 at 12:27
  • @phd - I have 3 github repos and I have 3 local projects that I want to push to them. I have 1 gitconfig and 1 sshconfig. 1 of the repos is declared as origin and the rest by their names. what can I do so that when I push every project as git push orgin master it reaches their respective git repos? For now I push 1 as origin and rest by their names. – Seeker90 Feb 28 '20 at 13:41
  • You cannot have multiple different `origin`s in one local repo. You can have 3 different `origin`s in 3 local repos. – phd Feb 28 '20 at 13:42

0 Answers0