0

I have multiple repositories that I am contributing to - Some are hosted on Github, and some on Assembla. Technically, my username varies between the two systems.

When I cd to a given repository's contents, I need to know the following:

  1. git knows who I am (did this with git config user.name, not git config --global user.name)
  2. whether or not I have authentication set up correctly via ssh

I am finding that git config --get user.name yields the correct info, but when I try to pull or commit, I get prompted for my username:

Username for 'https://github.com'

How can I ensure that my identity is linked correctly to both git worlds? I realize that #1 has nothing to do with SSH keys, but committing, although it's part of my setup, so I include it here for reference on what I'm trying to accomplish.

jml
  • 1,745
  • 6
  • 29
  • 55

1 Answers1

2

First of all, the config values for user.name, user.email have nothing to do with authentication to server (to allow you push, fetch, etc...), these are only for filling commits messages with author info

One think you could do, is to create a ssh key pair and use the same public key for assembla, and for github. Then, when cloning repositories from github make sure to use the SSH protocol

git@github.com:username/repositoryname.git

instead of

https://github.com/username/repositoryname

(The same for assembla)

if you config it properly, you shouln't be asked for username nor password

NOTE: git@github.com:username/repositoryname.git is a shorthand of ssh://git@github.com:username/repositoryname.git meaning the same

NOTE 2: the book on git-scm explains SSH protocol (among others) here: http://git-scm.com/book/en/Git-on-the-Server-The-Protocols, github always use "git" username and identifies github users using the ssh key

dseminara
  • 11,665
  • 2
  • 20
  • 22
  • Thanks. I'll try this and post back. Can you elaborate on why this other syntax is the case? I've run into this before. – jml Sep 11 '14 at 18:27
  • 1
    The differences between syntaxes is because one is for SSH protocol (e.g. git@github.com:kkaefer/node-cpp-modules.git) and the other is for https (e.g. https://github.com/kkaefer/node-cpp-modules.git), both options works fine, but https doesn't have passwordless authentication like the SSH one, the last is more practical if you doesn't want to type username and password on each pull/push – dseminara Sep 11 '14 at 18:31
  • I see this: http://git-scm.com/book/en/Git-on-the-Server-The-Protocols, which affirms what you've mentioned, but doesn't mention the `git@github.com:username/repositoryname` syntax. Is there another place I can find this information? – jml Sep 11 '14 at 18:32
  • 1
    Not exactly, I missed the final .git (editing now), but your link shows a section about "The SSH Protocol" , the full syntax is: ssh://user@server/project.git, and git allows you to remove the ssh:// to use the shorthand user@server/project.git – dseminara Sep 11 '14 at 18:35
  • Gotcha. Thank you so much, this is very helpful. I'll definitely mark your answer once I can clone and do a couple of tests. – jml Sep 11 '14 at 18:36