remote: Permission to *****newuser.git denied to *****1stusername - github

in Visual studio code
i spent a lot more time for this, I'm trying push my deleted project that is coming from 1st account github into an existing repository in new another account, but I'm getting error like this :
$ git push -u origin main
remote: Permission to username/project_name.git denied to first_account_username.
fatal: unable to access 'https://github.com/user_name/project_name.git/': The requested URL returned error: 403
i tried those command line for push an existing repository in new account, please let me know what'd i miss ?
git remote add origin https://github.com/user_name/project_name.git
git branch -M main
git push -u origin main

Git obviously tries to push code to your new repository using your old username. Add you new username explicitly to the URL:
git remote set-url origin https://user_name#github.com/user_name/project_name.git
Or use the SSH syntax:
git remote set-url origin user_name#github.com:user_name/project_name.git

Question :
$ git push -u origin main
remote: Permission to username/project_name.git denied to another_username
fatal: unable to access 'https://github.com/user_name/project_name.git/': The requested URL returned error: 403
Answer :
Above the Setting icon in visual studio code there will be a Account Sign in logo icon, click and check it is login with another account or not ?
If it is log in with another Account you will be get the same error continuously... So,
The solution is : You should sign out the other Account in the visual studio and then try in visual studio code terminal following code given below...
$ git push
Then it will ask username and password
you should enter the correct details and it will work perfectly.

Just see the same problem and here is my solution:
Before we generate the token. We need to enable some elements of "select scopes in github settings as show below.
I just select several elements and generate key. Therefore I can push the code after fill username and password(generated key).

Check what configuration helper you do have: it might have cached the wrong credentials (from the old users).
git config --global credential helper
Adjust you PATH to use said credential helper.
If you are on Windows, in a CMD, set a simplified PATH like:
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set "GH=%ProgramFiles%\Git"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"
Then type in the same CMD:
printf "Host=bitbucket.org\nprotocol=https\nusername=old_username" | git credential-manager-core erase
Replace:
manager-core by your actual credential helper, as returned by git config --global credential helper
old_username by the old username GitHub account
Then try again.

First check your credentials:
git config --global user.name
git config --global user.email
Then change with:
git config --global user.name "email"
git config --global user.email "email#email.com"
If you set another credential before, will have problem
use git config credential.username "username"

Related

Authentication failed and unable to link visual studio to git repository

I am trying to set up to build my first website and have been following an online tutorial. When trying to link visual studio and my GitHub repository, this is the message I get:
`
samanthacanela#samanthas-air Canela Street Art % git commit -m "initialized git repository"
[main 3a08e0a] initialized git repository
2 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 about.html
rename homepage.html => home.html (100%)
samanthacanela#samanthas-air Canela Street Art % git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
samanthacanela#samanthas-air Canela Street Art % git push --set-upstream origin main
The authenticity of host 'github.com (140.82.112.3)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
samanthacanela#samanthas-air Canela Street Art %
`
I'm an absolute beginner. What the hell am I doing wrong?
I was following along a tutorial and they lost me.
Based on my understanding, I can see that you may haven't setup the origin remote URI. To fix that issue, you'll need to follow these steps.
Logging into git (If you aren't already)
Run these commands to set your display name and email when pushing:-
$ git config --global user.name "Your name here"
$ git config --global user.email "your_email#example.com"
Using HTTPS access method (recommended)
Using GitHub CLI, you can run $ git auth login and follow the steps to login.
Or if you're using GCM (Git Credential Manager)* refer to this article by GitHub
* GCM is another way to store your credentials securely and connect to GitHub over HTTPS. With GCM, you don't have to manually create and store a personal access token, as GCM manages authentication on your behalf, including 2FA (two-factor authentication).
Using SSH access method
If you clone with SSH, you must generate SSH keys on each computer you use to push or pull from GitHub. For more information, see "Generating a new SSH key."
Setting up your repository
** Make sure to run these commands inside your git environment and not globally.
#Set a new remote
git remote add origin github.com/example/example.git
#Verify new remote
git remote -v
Basically, a common cause for an error after following these steps is cloning using HTTPS method instead of SSH. You can correct this by going to your repository, clicking "Clone or download", then clicking the "Use SSH" button above the URL field and updating the URL of your origin remote like this:
$ git remote set-url origin git#github.com:ex-user/example.git
And that forces the source to be SSH.
If this still gives you an error, please refer to this answer.
For more help, refer to this document.

How to resolve "fatal: unable to access " error

I'm a beginner to GitHub.I need to send a pull request to the master branch.
when i typed the code
git push origin master
It gives me the error
fatal: unable to access
'https://github.com/www-prolificme-com/mahawiki/': The requested URL
returned error: 403
Updated
You mentioned you are trying to pull from git but the command is git push. Anyways, most probably you are getting this error because your repo url is not set locally.
If this is the first time you are sending git request from your system, you might want to setup your username by git config --global user.name "John Doe"
If you have already used git on your system, try checking the git configuration on your system using git config --list command to check whether your repo URL is setup or not.
If the url is not setup run git remote set-url origin https://github.com/www-prolificme-com/mahawiki/
Run git remote -v to verify if your url is setup
git add .
git commit -m "your message"
git push origin master
Remove/Update the saved credentials:
Click Start
Search for 'Credential Manager'
Select 'Windows Credentials Manager' > 'Windows Credentials'
Search for the credentials that you want to remove/update
Click on the credential entry > Click 'Edit' or 'Remove'
your repo is not setting locally
so, you seemed crash message
first
git config --list
to showing your git repo set list
and
git remote set-url origin <your git repo address>
to access git repo and git add . to add your files to git container
git commit -m "your git commit message"
this is your git commit message version or anything possible
git push origin master
finally your files pushing on git repo
it's done!
try it
I got this same problem then I try to this below command.
step 1:
git config --global user.email "user email"
step 2:
git config --global user.name "user name"
After running those commands, you can use this command to push your code:
git push origin master
Even if you set all credentials and other setups in the local machine, you might face this problem.
Currently, GitHub uses 'personal access token' so when or after creating personal access token you must check the Select scopes.
You select all you need and then push again.
It will be pushed successfully.
If nothing working please check if you have checked the below checkboxes while creating token

Cannot push to my repo on github inspite of correct username and email in git config

git config shows correct user name and email and yet I cannot ever git push to my own repo on GitHub. It always says some old username that was used
git config user.name mqshaikh8
git config user.email mqshaikh8#gmail.com
git push origin master
remote: Permission to mqshaikh8/amigo.git denied to kshaikh99.
fatal: unable to access 'https://github.com/mqshaikh8/amigo.git/': The requested URL returned error: 403
git remote --v
origin https://github.com/mqshaikh8/amigo.git (fetch)
origin https://github.com/mqshaikh8/amigo.git (push)
It happened to me quite a bit, mostly after a typo in my password and couldn't ever type a password again.
Usually installing git bash again over the old installation fixes the problem.
If you're using the default settings/windows credentials the please see this github issue on git for desktop to help you on this matter.
This SO post on how to remove git credentials might also help.
Finally what worked is the following:
I was logged into windows as kshaikh99. Since git integrated with windows credential manager, it had cached the kshaikh99 username and password and regardless of what's in git config user.name and user.email, it always used that credential to authenticate and that's why it was failing.
I just signed off and signed into windows as mqshaikh8. Then when I tried to git push origin master, I got a windows credential dialog box to enter my mqshaikh8 username and password. I entered that and it works with no issues.

GitHub: invalid username or password

I have a project hosted on GitHub. I fail when trying to push my modifications on the master. I always get the following error message
Password for 'https://git#github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://git#github.com/eurydyce/MDANSE.git/'
However, setting my ssh key to github seems ok. Indeed, when I do a ssh -T git#github.com I get
Hi eurydyce! You've successfully authenticated, but GitHub does not provide shell access.
Which seems to indicate that everything is OK from that side (eurydyce being my github username). I strictly followed the instructions given on github and the recommendations of many stack discussion but no way. Would you have any idea of what I may have done wrong?
After enabling Two Factor Authentication (2FA), you may see something like this when attempting to use git clone, git fetch, git pull or git push:
$ git push origin master
Username for 'https://github.com': your_user_name
Password for 'https://your_user_name#github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/your_user_name/repo_name.git/'
Why this is happening
From the GitHub Help documentation:
After 2FA is enabled you will need to enter a personal access token instead of a 2FA code and your GitHub password.
...
For example, when you access a repository using Git on the command line using commands like git clone, git fetch, git pull or git push with HTTPS URLs, you must provide your GitHub username and your personal access token when prompted for a username and password. The command line prompt won't specify that you should enter your personal access token when it asks for your password.
How to fix it
Generate a Personal Access Token. (Detailed guide on Creating a personal access token for the command line.)
Copy the Personal Access Token.
Re-attempt the command you were trying and use Personal Access Token in the place of your password.
Related question:
https://stackoverflow.com/a/21374369/101662
https://git#github.com/eurydyce/MDANSE.git is not an ssh url, it is an https one (which would require your GitHub account name, instead of 'git').
Try to use ssh://git#github.com:eurydyce/MDANSE.git or just git#github.com:eurydyce/MDANSE.git
git remote set-url origin git#github.com:eurydyce/MDANSE.git
The OP Pellegrini Eric adds:
That's what I did in my ~/.gitconfig file that contains currently the following entries [remote "origin"] url=git#github.com:eurydyce/MDANSE.git
This should not be in your global config (the one in ~/).
You could check git config -l in your repo: that url should be declared in the local config: <yourrepo>/.git/config.
So make sure you are in the repo path when doing the git remote set-url command.
As noted in Oliver's answer, an HTTPS URL would not use username/password if two-factor authentication (2FA) is activated.
In that case, the password should be a PAT (personal access token) as seen in "Using a token on the command line".
That applies only for HTTPS URLS, SSH is not affected by this limitation.
Solution steps for Windows users:
Control Panel
Credential Manager
Click Windows Credentials
In Generic Credential section ,there would be git url, update username and password
Restart Git Bash and try for clone
Note:
If you didn't find git url in Generic Credential section then follow below answer
https://stackoverflow.com/a/55858690/7372432
If like me you just updated your password and ran git push to run into this issue, then there's a super easy fix.
For Mac users only. You need to delete your OSX Keychain access entries for GitHub. You can do it via terminal by running the following commands.
Deleting your credentials via the command line
Through the command line, you can use the credential helper directly to erase the keychain entry.
To do this, type the following command:
git credential-osxkeychain erase
host=github.com
protocol=https
# [Now Press Return]
If it's successful, nothing will print out. To test that it works, try and clone a repository from GitHub or run your previous action again like in my case git push. If you are prompted for a password, the keychain entry was deleted.
When using the https:// URL to connect to your remote repository, then Git will not use SSH as authentication but will instead try a basic authentication over HTTPS. Usually, you would just use the URL without a username, e.g. https://github.com/username/repository.git, and Git would then prompt you to enter both a username (your GitHub username) and your password.
If you use https://something#github.com/username/repository.git, then you have preset the username Git will use for authentication: something. Since you used https://git#github.com, Git will try to log in using the git username for which your password of course doesn’t work. So you will have to use your username instead.
The alternative is actually to use SSH for authentication. That way you will avoid having to type your password all the time; and since it already seems to work, that’s what you should be using.
To do that, you need to change your remote URL though, so Git knows that it needs to connect via SSH. The format is then this: git#github.com:username/repository. To update your URL use this command:
git remote set-url origin git#github.com:username/repository
Instead of git pull also try git pull origin master
I changed password, and the first command gave error:
$ git pull
remote: Invalid username or password.
fatal: Authentication failed for ...
After git pull origin master, it asked for password and seemed to update itself
2FA is enabled and getting error remote: Invalid username or password.
fatal: Authentication failed for
If you set 2FA is enabled in GitHub you will need to enter a personal access token instead of a 2FA code and your GitHub password.
How to fix it
https://github.com/settings/tokens generated token
Copy the Personal Access Token
Now enter Personal Access Token in the place of your password during git operation
just try to push it to your branch again. This will ask your username and password again, so you can feed in the changed password. So that your new password will be stored again in the cache.
This is the answer.
Set the github token:
https://github.com/settings/tokens
And then:
git remote set-url origin https://[token]#github.com/your_repository
I am getting this while cloning app from bitbucket:
Cloning into 'YourAppName'...
Password for 'https://youruser id':
remote: Invalid username or password
I solved it. Here you need to create password for your userid
Click on Your profile and settings
Then Create app password choose your name password will generated ,paste that password to terminal
That problem happens sometimes due to wrong password. Please check if you are linked with AD password (Active Directory Password) and you recently changed you AD password but still trying git command with old password or not.
Update old AD password
Control Panel > Credential Manager > Windows Credential > change github password with my new AD password
I have got the success using the following commands.
git config --unset-all credential.helper
git config --global --unset-all credential.helper
git config --system --unset-all credential.helper
Try and let me know if these are working for you.
No need to rely on Generating a Personal Access Token and then trying and use Personal Access Token in the place of your password.
Quick fix is to set your remote URL to point to ssh not https.
Do this git remote set-url origin git#github.com:username/repository
I did:
$git pull origin master
Then it asked for the [Username] & [Password] and it seems to be working fine now.
If you have just enabled 2FA :
Modify hidden config file in ./git hidden folder as follow :
[remote "origin"]
url = https://username:PUT_YOUR_2FA_TOKEN_HERE#github.com/project/project.git
Try this:
# git remote set-url origin git#github.com:username/repository
Run Below command, and after than on every push and pull it will ask you to enter the username and password.
git config credential.helper ""
now when you pull/push you will be asked for git credentials. weather you are running through command prompt or Intellij Git.
Disabling 2 factor authentication at github worked for me.
I see that there is a deleted answer that says this, with the deletion reason as "does not answer the question". If it works, then I think it answers the question...
You might be getting this error because you have updated your password. So on Terminal first make sure you clear your GitHub credentials from the keychain and then push your changes to your repo, terminal will ask for your username and password.
In case you get this error message in this situation:
using github for entreprise
using credential.helper=wincred in git config
using your windows credentials which you changed recently
Then look at this answer:
https://stackoverflow.com/a/39608906/521257
Windows stores credentials in a credentials manager, clear it or update it.
Control panel
Credential manager
Look for options webcredentials and windows credentials
in either one you will find github credentials fix it with correct credentials
open new instance of git bash you should be able to perform your git commands.
This worked for me, I was able to pull and push into my remote repo.
I had the same issue. And I solved it by changing the remote branch's path from https://github.com/YourName/RepoName to git#github.com:YourName/RepoName.git in the repo's settings of the client app.
I'm constantly running into this problem.
Make sure you set git --config user.name "" and not your real name, which I've done a few times..
I just disable the Two-factor authentication and try again. It works for me.
Since you probably want to keep 2FA enabled for your account, you can set up a ssh key and that way you won't need to type your Github credentials every time you want to push work to Github.
You can find all the ssh setup steps in the documentation. First, make sure you don't currently have any ssh keys (id_rsa.pub, etc.) with $ ls -al ~/.ssh
I fixed my issue by installing GitHub CLI and running gh auth login
See:
https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git#github-cli
I had the same issue
$ git clone https://github.com/sample-url.git
Cloning into 'Project'...
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/sample-url.git/'
I just git init first and then git clone <clone-url>
git init
git clone https://github.com/your-clone-Url
It worked for me.
There is a issue on Windows using cmd-Greetings
There is a issue on Windows using cmd-Greetings who will not let you clone private repositories. Remove that cmd-greeting described in this documentation (keyword Command Processor):
Known-Issues
I can confirm that other clients like SourceTree, GitKraken, Tower and TortoiseGit affected to this issue too.
There are many reasons why this might happen. In my case, none of the solutions worked. In particular, git pull origin master did not ask me for my username and password.
I was on Windows with a github password recently changed. I was using the credential manager to manage my password. Here is what worked for me:
Confirm you are using the credential manager for git:
git config --list
…
credential.helper=manager
Run a new command prompt as administrator
List all stored credential with cmdkey /list from C:\WINDOWS\system32>
Remove the github target with cmdkey /delete:<target name>. In my case, the target name was github.<companyname>.com
Open a new prompt and run a git command. You should get a popup asking for your usernmame and password. After providing the new credentials, it won't ask you for it again.
When I faced this issue all I did to resolve it was to Generate new token from my github dashboard and paste the following code in my terminal
$ git remote set-url origin https://your-github-username:your-github-token#github.com/your-github-username/your-github-repo.git

problem in pushing to github

I have created a repository on github named pygame. Created a clone and added files and commited.but when I attempt to push I receive the following error:
git push -u origin master
error: The requested URL returned error: 403 while accessing https://github.com/amalapk/pygame/info/refs
fatal: HTTP request failed
I can ssh to git#github.com and receive the notice that I logged in successfully, but can't push to my repository.
I recently experienced this problem when setting up a new clone of my github project.
You need to include your username in the URL to your project, in the form
https://user#github.com/project/...
For example, the URL provided for my test github is this:
https://github.com/jdblair/test.git
If I add my username to it, like this, then I'm able to push and pull from github with no problem:
https://jdblair#github.com/jdblair/test.git
It is easiest to use the URL that contains the username starting from when you clone a project.
You can change the URL for an existing project like this:
git remote set-url origin https://user#github.com/project/foo/bar.git
You can use the ssh authentication instead if you want, but that's a separate setup process.
Github now is asking us to use git 1.7.10 or later:
https://help.github.com/articles/error-the-requested-url-returned-error-403
The GitHub Remote page mentions the read/write addresses for a repo:
Make sure your clone address is like:
https://github.com/username/yourRepo.git
And that you have defined:
git config --global user.name "Firstname Lastname"
git config --global user.email "your_email#youremail.com"
Should you use a git address (without ssh), you would also need:
git config --global github.user username
git config --global github.token 0123456789yourf0123456789token # no longer needed
(with your token coming from “Account Settings” > Click “Account Admin.”)
Update 2013: you still can generate a token (see "Creating an access token for command-line use"), but you would use it as a password for https url.
Actually, if you activate the 2FA (two-factor authentication) mechanism on GitHub, you will need a token for your https url (because your regular password would trigger the second-step verification).
See "Configure Git clients, like GitHub for Windows, to not ask for authentication"
See more at "Which remote URL should I use?".
It's all in the remote.
Change your current remote from https://github.com/amalapk/pygame.git to git#github.com:amalapk/pygame.git and enjoy.
To do this... (assuming your current remote is called origin)
git remote set-url origin git#github.com:amalapk/pygame.git
In my case getting rid of such error message was resolved this way:
Person was simply added to github repository as a colaborator.
Thats it - error vanished magically.
Committing to github from server this is what worked for me in the terminal or git bash
To create a remote to github.com try:
git remote add origin https://put your username here#github.com/put your git username here/put your repository name here
To change the remote just do:
git remote set-url origin https://put your username here#github.com/put your git username here/the name of your repository here
Please follow the instructions on http://help.github.com/create-a-repo/
You have cloned your repository with the public read only url.
RTFM