I am on Mac OSX, git version 1.8.5.2 (Apple Git-48)
I had a git submodule in a git repo that had (to my knowledge) only ever been cloned, pulled, committed, merged and pushed using one git user and rsa key. I have many other pairs of users and keys but no others were specified in the ~/.gitconfig file.
When this submodule had the remote of https://github... etc. It would allow me to commit with the correct username and email being applied but when pushing, would tell me that:
remote: Permission to some_username/project.git denied to user2.
fatal: unable to access 'https://github.com/some_username/project.git/': The requested URL returned error: 403
However when I removed the https://... remote and instead used the git#github.com:some_username/project.git remote, it works correctly.
Is this a bug with git or github? Was there any other way to fix it? Both these users have their associated rsa keys associated on their github accounts.
Is this a bug with git or github?
No: with https url, you need to add the login in the url for git to know what credential to ask for:
cd /path/to /your/submodule
git remote set-url origin https://yourLogin#github.com/yourLogin/yourRepo
An ssh url would use automatically your key (in $HOME/.ssh/id_rsa.pub) which, if published to your account (and if your account is the owner or collaborator of the GitHub repo)
Related
Is there a quick way to just log out and log back in with a different account on git in cmd on windows?
I tried:
git config --global --unset user.name
git config --global --unset user.mail
git config --global --unset credential.helper
so I understand I should have been logged out with the old_user_name?
Then I used:
git config --global user.name "new_user_name"
git config --global user.email "new_email"
git push origin master
I got a massage:
remote: Permission to new_user_name/new_repo.git denied to old_user_name.
fatal: unable to access 'https://github.com/new_user_name/new_repo.git/': The requested URL returned error: 403
That means I'm still logged in with the old account. What else can I do?
The user.name and user.email settings are not logins, in any way, shape, or form. (The credential.helper setting is useful here, but just unsetting it is probably not right.)
Whenever you make a new commit (by, e.g., running git commit), Git needs to know what user name and email address to put in the new commit. Git gets these by reading user.name and user.email at that time. That's all they're for: to set these in new commits.1
When you run git push, you do (usually2) need to authenticate in order to send your new commits to some other Git repository. Git does not do this authentication. Git relies on other programs to do it. Those other programs include:
Web servers, via https URLs: here, Git has to send a user name and password or PAT or some other secret to the web server. Git gets these from:
the URL, if they're in the URL;
a credential helper, which you may configure: Windows Git comes with a Windows-specific credential helper, macOS Git comes with a macOS-specific credential helper, and so on; or
as a last resort, reading the user name and password from the keyboard.
Generally the right way to do this is with a credential helper. See the gitcredentials documentation and the specific credential helpers available for your particular Git installation. The problem with method #1 is that the password is visible right there in the URL by anyone looking at your computer; the problem with method #3 is obvious.
Unsetting the credential helper gets you the default for your system. This might not be the best thing to do. For Windows systems, see Remove credentials from Git and in particular VonC's answer here.
Secure Shell (SSH): here, Git simply runs the ssh command. Windows systems come with their own ssh command these days, and Git-for-Windows comes with its own ssh command because the older Windows systems either lacked ssh entirely or provided an inadequate version, so on Windows systems, you must make sure that you configure and use the correct ssh (whatever that may be for your installation).
Since you are using an https:// URL, you will need to set up your credential system. If you wish to use ssh:// URLs, set up ssh.
1Note that git rebase works by copying existing commits to new and (supposedly / intended-to-be) improved ones, so this too uses the settings: it's making new commits.
2One can set up a completely open, anonymous network where anyone can push anything at any time, but these are way too easy to abuse, so nobody does this in practice.
I want to clone a repository and I ran into permission issues,
I tried to set up my username and email but keep getting errors
I used
git config --global user.name "yusuf-uthman"
git config --global user.email "yusufuthman57#gmail.com"
but didnt get any notification wether its accepted or not.
Uthman#DESKTOP-30QGK3L MINGW64 ~/Desktop/Scripts/hng_internship5.0
$ git config --global user.name "Uthman Yusuf"
Uthman#DESKTOP-30QGK3L MINGW64 ~/Desktop/Scripts/hng_internship5.0
$ git config --global user.email "yusufuthman57#gmail.com"
Uthman#DESKTOP-30QGK3L MINGW64 ~/Desktop/Scripts/hng_internship5.0
$ git clone git#github.com:yusuf-uthman/hng-internship.git
Cloning into 'hng-internship'...
Warning: Permanently added the RSA host key for IP address '192.30.253.113' 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.
How do I clone the repository without getting the error?
The failure comes from cloning your GitHub repo via SSH URLs. To use that process, one needs to add your public SSH key in your repository.
Instead use HTTP URL method to clone which will most likely circumvent that error.
Use:
HTTP URLs: https://github.com/yusuf-uthman/hng-internship.git
instead of:
SSH URLs: git clone git#github.com:yusuf-uthman/hng-internship.git
but didnt get any notification wether its accepted or not.
Username and Email are just settings in you git config file, no one will accept or decline it. If you commit, the value of the settings will be used to determine the commits author and committer.
Access rights to a repository are usually managed via ssh keys. See Connecting to GitHub with SSH.
Prefacing this with I am very new to git and github.
I set up a repo on github, as user zzz, and it is correctly listed in my local (repo-specific) git config file, which has entries like the following when I do 'git config --local --list':
remote.origin.url=https://github.com/zzz/myrepo.git
user.name=zzz
user.email=yyy#example.com
But when I do do git push origin master, it get 403 denied to user 'xxx'... a user which corresponds to a completely separate github account. How do I fix this? And why is it picking up user 'xxx' when that is not the user i carefully specified in the local config file? I am on windows 7 machine.
Git store credentials in Windows, clear them referring below image:
Run your git push command, it will prompt you to enter credentials again.
Image Courtesy - Remove credentials from Git
I used my old github account and now that is deactivated and i have a new one now. I want it to communicate with my new github username. I've tried many internet solutions and re-installing git and the command line tools. Whenever i type in git remote -v
origin https://github.com/OldUsername/App.git (fetch)
origin https://github.com/OldUsername/App.git (push)
This account is now deactivated so there is no way to use it, I've tried doing the
git config --global user.email "YOUR EMAIL ADDRESS"
git config user.name "Username"
I've been trying for hours and still can't figure out how to get my command line to be able to push to new projects under my new username.
That's the push setting for the remote in your repository config.
Either go hand edit /.git/config or try something like
git remote set-url origin https://github.com/NewUsername/app.git
Remotes are part of a local repository. You can add, remove, rename, or reconfigure them with various git-remote subcommands. You might consider just nuking the current repository directory if it doesn't contain anything you value and cloning or creating a new one.
Alternatively, you can set the URL for a remote using:
git remote set-url origin <new URL>
Currently I have an website on a .zip file containing also the .git directory and all the history. I want it to be imported into an Assembla git repository preserving the history of all previous changes. Is there an easy way of doing it?
extract your zip, navigate to it in your shell, and do git push <git assembla url> :. this should push all the refs to the new assembla repo.
If you cannot push to an assembla repo, check your ssh keys, like in this thread.
ssh -v git#git.assembla.com
And see if there was not too much login errors in your tries:
Your IP was added to blacklist due login failure to our server.