2

I have my keys in ~/.ssh/ and on other computers I can push and pull from the repo in question.
Why on one computer do I always need to enter my github username/password but not on others?

What could I change to avoid this and use my ssh keys instead ?

2

This can be changed by changing the authentication protocol method from https to ssh

One option would be to rename or delete the existing repo and then 'reclone' with the different method. So after mving or rm -ring the current repo, the clone command will be something like

git clone git@github.com:user_name/repo_name.git

You can see the difference in the two approaches with the git config -l command:

For https:

...
remote.origin.url=https://github.com/user_name/repo_name.git
...

For ssh

...
remote.origin.url=git@github.com:user_name/repo_name.git
branch.master.rebase=true  # This was also created in the ssh method

...

You can see the difference in the .git/config file for each repo:

Note the change in 'url' below. Plus addition of rebase = true in ssh

http

[core]
  repositoryformatversion = 0 
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  url = https://github.com/user_name/repo_name.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master

ssh

[core]
  repositoryformatversion = 0 
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  url = git@github.com:user_name/repo_name.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master
  rebase = true

So if you want to just change the authentication method without 'recloning' the entire repo you can just edit the projects .git/config and change

  url = git@github.user_name/repo_name.git

to

  url = https://github.com/user_name/repo_name.git

plus add

rebase = true

at the bottom, in the "[branch "master"]" section

2

The easiest way is to create a ~/.netrc file with the following contents:

machine github.com
login YOUR_GITHUB_USERNAME
password YOUR_GITHUB_PASSWORD

(as shown here: https://gist.github.com/ahoward/2885020)

You can even close up the permissions on this file so that no one can read your password by typing:

chmod 600 ~/.netrc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.