How to redefine a local user in the git repository? I am registering new user.name and user.email, but git is still trying to push by global settings.

Error after git push origin master

 remote: Permission to имя_локальноС/Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΉ.git denied to имя_глобальноС. fatal: unable to access 'https://github.com/имя_локальноС/Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΉ.git/': The requested URL returned error: 403 

Update 1.
In git log author of commits recorded a locally defined user (name and email).
But when pushing, he apparently doesn’t care, he turns to global settings (assumption). What to do to push?

  • The author of commits is one thing, the user under whom you are logged in is completely different. - Nick Volynkin ♦
  • @NickVolynkin do i need to change the authorization in the git system? Is it not done through the config? - stackanon

1 answer 1

The GitHub documentation says that this error is related to the Deploy key. Deploy key is an SSH key.

Due to the different users on the remote repository and on the local, you can establish a connection through the public key.

Therefore, you need not to dig into this file:

 ~/.gitconfig 

More specifically, you need an SSH key that must be on your local machine and the same key must be added to the access keys of the desired remote repository.

The instructions below are for * nix machines.

First you need to check the existence of existing public keys. To check for the presence of a public SSH key, you need to register in the terminal:

 ls -al ~/.ssh 

By default, public key names are displayed as follows:

 id_dsa.pub id_ecdsa.pub id_ed25519.pub id_rsa.pub 

If there is no such key or for some reason you do not want to use existing ones, then you can generate a new public SSH key:

 $ ssh-keygen -t rsa -b 4096 -C "твоя_ΠΏΠΎΡ‡Ρ‚Π°@ΠΏΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹ΠΉ_ΠΏΠΎΠ΄Π΄ΠΎΠΌΠ΅Π½.Π΄ΠΎΠΌΠ΅Π½" 

After the command above, a new SSH key will be created, which will be accompanied by mail as a label.

The following is displayed in the Terminal:

 Generating public/private rsa key pair. Enter file in which to save the key (/Users/username/.ssh/id_rsa): 

By pressing Enter, the key will be created in the default directory. Lines will appear below, where you will need to enter a password-phrase and repeat it.

 Enter passphrase (empty for no passphrase): [Напиши Ρ„Ρ€Π°Π·Ρƒ] Enter same passphrase again: [Напиши Ρ„Ρ€Π°Π·Ρƒ] 

After the generated key, you need to add this key to the SSH-agent. First you need to make sure that the SSH-agent is activated:

 eval "$(ssh-agent -s)" 

It should display something like the following:

 Agent pid 39591 

After that, it remains to add the SSH key to the SSH agent:

 $ ssh-add ~/.ssh/id_rsa 

Now, let's add the key to the access keys on the remote repository. First, add the SSH key to the clipboard:

 $ pbcopy < ~/.ssh/id_rsa.pub 

Do the following:

  1. Open GitHub in a browser and log in.
  2. Go to Settings
  3. Open the SSH and GPG keys section
  4. Push New SSH key
  5. Paste from the clipboard in the section Key data
  6. Fill the title
  7. Add the key and confirm the addition by entering the account password.

Profit. You should establish a connection between the local machine and the remote repository via an SSH key. The solution is based on information that GitHub tech support offers.

  • This is something wrong, I'm trying to redefine the global user to local, so that there are commits from it in history. I have windows and https. - stackanon