1

I have in my ~/gitconfig and in my (repo)/.git/config:

[user]
    name=sboesch
    email = stephen.boesch@mycompany.com

Are they working? Seems so ..

$ git config user.email
stephen.boesch@mycompany.com
[cloudera@localhost hwspark]$ git config user.name
sboesch

But when doing a push my old credentials (specifically username=javadba) are being used instead:

[cloudera@localhost hwspark]$ git push
remote: Permission to Mycompany-Spark/spark.git denied to javadba.

What configuration step am I missing here?

**UPDATE* more info - from

git config -e

Output:

[remote "origin"]
        url = https://github.com/<companyRepoName>/spark.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "ctx"]
        remote = origin
        merge = refs/heads/ctx
[user]
        email = stephen.boesch@mycompany.com
        name = sboesch
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

2 Answers2

1

Your main (global) git config file sets your user name and email for new commits you add (to any repository), but (at least normally) does not affect anything else.

Your per-repository git config file contains more-specific instructions, like "the URL(s) to use for fetch and push operations to a named remote". The usual default remote is named origin:

$ git config --get remote.origin.url
git://git.kernel.org/pub/scm/git/git.git

or you can just run git config -e to open up the per-repository config file in your configured editor; you should see something like this (this is for my copy of the git source):

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git://git.kernel.org/pub/scm/git/git.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

The url sets both fetch and push URLs, unless there's a pushurl which sets the push URL.

If the push URL is, e.g., ssh://user@host/path/to/repo.git, then git will invoke ssh using user as the user name. The ssh transport has its own, entirely-separate, methods of doing authentication: git just invokes ssh and lets ssh take care of everything.

For more about that, see, e.g., VonC's answer to this question.

If the push URL uses some other transport, you'll need authentication based on that other transport.

[Edit] You're using https authentication. See Git push requires username and password: the simplest fix is to switch to ssh authentication, but if you want to keep using https authentication, check out the other answers. (The details depend on your own host OS.)

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775
  • Hi, i have updated the OP to reflect that the settings are/were both in the global ~/.gitconfig and in the repo-local .git/config – WestCoastProjects Aug 30 '14 at 01:12
  • 1
    You can *override* global settings in the local config, but again the `user.name` and `user.email` are *not* the interesting items here, it's the `pushurl` if set, or the `url` if not, that is the next key item. – torek Aug 30 '14 at 01:23
  • It is still unclear to me specifically where the issue is. In any case I have updated the OP to show the git config -e – WestCoastProjects Aug 30 '14 at 04:14
  • OK, this indicates that you're using https authentication. See edit. – torek Aug 30 '14 at 04:29
  • My original question mentions that the git auth error is showing the wrong username (javadba instead of stephenb). I still do not see an explanation of that particular error mode in your answer here. – WestCoastProjects Aug 30 '14 at 04:33
  • It still depends on whether you're on OSX or Linux (as far as I know; I haven't used https authentication on either one). If you're on Linux it may be reading this from `~/.netrc`. But the main thing here is, you've gone past my knowledge of mixing git with https. (I use ssh.) I can't tell you for sure where it *is* coming from, but it's definitely not coming out of any of the standard git config files. – torek Aug 30 '14 at 05:03
  • OK, well I have upvoted anyways since you have added some useful info. Will await more answers for actual award. – WestCoastProjects Aug 30 '14 at 07:19
  • Not really a fully answered question, but i'm awarding since it's all that we got here. – WestCoastProjects Sep 27 '14 at 00:23
0

You can simply add your username in your config remote "origin" URL (I'd recommend using SSH instead of HTTPS).

Run git config -e to open your repository config file.

Add your username like below example:

[remote "origin"]
        url = git@github.com-<your-username>:<company-repo-name>/spark.git
        fetch = +refs/heads/*:refs/remotes/origin/*