I want to access my github repo from two different computers, using one github account. Everything works fine on the computer that I created the repo on. It's just this second computer that is messed up
I successfully set up a repo on github. Now I want to clone it on another machine so that I have push/pull access.
I made a public key on the second machine and specified my email as the email associated with github
ssh-keygen -t rsa -C "MYEMAIL#gmail.com",
then copied it to the SSH keys on the github website.
I cloned the repo like this
git clone https://github.com/MYUSERNAME/MYREPO
Next I edited the "url = " line in the .git/config file so that it said
url = ssh://git#github.com/MYUSERNAME/MYREPO
Both of my computers are configured to have the same user.name, USERNAME and github.user based on my github account settings. I also configured the API token with the same token on each computer.
git config --global user.name "FIRST LAST"
git config --global user.email "MYUSERNAME#gmail.com"
git config --global github.user MYUSERNAME
Yet, when I try to push, this happens:
>> git push origin master
Permission denied (publickey).</code>
fatal: The remote end hung up unexpectedly
The issue was a naming one, as the OP erin mentions in the comments:
I named my public key "github.pub" rather than "id_rsa.pub"
For ssh to work, using default naming convention is important.
See, for instance:
"git clone with ssh issue"
"GITHUB setup - no address associated with name"
Related
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.
So, I have my work computer and that is connected to my GitHub Enterprise Account (github.company.com) on the terminal. Now I want to set up my personal account (github.com) on here too.
I've been following this tutorial - https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574
and on step 3 when I have to create my config file should my HostName be github.company.com or github.com? Can I have any (meaningful) name for Host? Also, what does User here mean?
Also, how do I switch between both these accounts on the terminal - i.e. my personal and my enterprise account? There are certain things I need to commit from my personal account, and use the enterprise account with the rest.
Detailed steps to use two GitHub accounts on the same PC as below:
1. Create SSH key for the github.company.com account
If you already added the SSH key to your github.company.com account, then skip this step.
First, use ssh-keygen to create id_rsa and id_rsa.pub in C:\Users\username\.ssh.
Then, add the content of id_rsa.pub file as a SSH key in github.company.com account.
2. Create SSH Key for your personal account github.com
Use ssh-keygen -t rsa -C "email address for the personal github account", and save the key in /c/Users/username/.ssh/id_rsa_personal.
Now add the content of id_rsa_personal.pub file as a SSH Key in your personal GitHub account.
3. Config the two SSH Keys
In C:\Users\username\.ssh diectory, create a config file with below content:
Host github.company.com
HostName github.company.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
4. Work with the two GitHub accounts by SSH protocol
You can clone your github.company.com account by:
git clone git#github.company.com:companyaccountname/reponame
And then add the personal account as a remote in the local repo by:
git remote add personal git#github-personal:personalaccountname/reponame
To get the file from personal account to company repo by below commands:
git merge upstream master --allow-unrelated-histories
# make changes
git add .
git commit -m 'add the changes from peronal repo'
git push origin master
To commit/push changes from local company repo by the committer of the personal repo, you just need to re-config the username and email before committing changes in the local repo:
git config user.name <personal github account username>
git config user.email <email for login the personal github account>
When you want to commit changes with the company account, just re-config username and email again before committing changes.
OS: Mac Mojave
I have a personal GitHub account that I contribute to, and some other corporate accounts that I contribute to as well.
On my private account, I created a private repo, and what I would like to do, is check some source code, that I have on my local disk, into that repository.
From a Mac terminal, I made sure I was in the directory I wanted to check into the empty private repo, and then I did the following:
git init
git add .
git commit -m "checking existing files into my private repo"
I then went to my private repo, and copied the URL, let's say:
https://github.com/myaccount/myPrivateRepo
I then did the following:
git remote add origin https://github.com/myaccount/myPrivateRepo
and then did:
git remote -v
And got the following response:
origin https://github.com/myaccount/myPrivateRepo (fetch)
origin https://github.com/myaccount/myPrivateRepo (push)
Which I assumed means: everything checks out OK
Then I tried to push, using:
git push -u origin master
Which gave me the following error message:
remote: Repository not found.
fatal: repository 'https://github.com/myaccount/myPrivateRepo/' not found
Any ideas?
I trued changing the remote to:
git remote add origin git#github.com:myaccount/myPrivateRepo.git
and when I tried to push, I got the following error:
The authenticity of host 'github.com (192.30.255.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.113' (RSA) 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.
The remote you add should be of this form:
git#github.com:myaccount/myPrivateRepo.git
Also set your git email address to match those of your github account:
git config user.email "you#example.com"
git config user.name "Full Name"
You can also edit these by editing the .git/config file.
Finally, make sure your SSH public key is correctly set up:
https://github.com/settings/keys
Your public key should be located in cat ~/.ssh/id_rsa.pub. You can print it with:
cat ~/.ssh/id_rsa.pub
If you don't have an SSH public key yet, then follow this guide:
https://help.github.com/en/articles/connecting-to-github-with-ssh
I have two github account--tuomao and maomao1234,my computer global config user.name is tuomao and I add an ssh key to my computer for tuomao. I use maomao1234 to create a repository Hospital.
Then I clone it into my computer. I have change this repository setting with following instruction.
git config user.name maomao1234
git config user.email myemail
Then I edit some file of the repository and commit my changes,here is my commit log
tuomao#TUOMAO-PC /k/桌面资料/code/temp2/Hospital (master)
$ git log
commit 5a35e6dad5caf21c482db9e5e7fd62e01ee2b807
Author: maomao1234 <944925840#qq.com>
Date: Fri May 6 11:51:55 2016 +0800
from the log,we can see that my commit user is right.
However,when I use git push to push my commit,it happens error
$ git push https://github.com/maomao1234/Hospital.git
remote: Permission to maomao1234/Hospital.git denied to tuomao.
fatal: unable to access 'https://github.com/maomao1234/Hospital.git/': The requested URL returned error: 403
form the error log,we can see the push user is not right.Why I have already change the repository user and the commit user is right but the push user is fault?
how can I push my changes with user maomao1234?
git push https://... means your ssh keys are completely ignored, since you are using the https protocol.
from the log,we can see that my commit user is right.
This has nothing to do with the account used to push: you can create any commit with any git config user.name and still be able to push (with https or ssh) to a repo, provided you use, at push time, the right account or ssh key.
Check git remote -v to see exactly what remote url is used.
An https one should ask you for a user and password.
An ssh one means you need to make sure %HOME%\.ssh\id_rsa.pub is the key associated to maomao1234 and not tuomao.
If you need to manage multiple ssh keys, see "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?".
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