WestCoastProjects
WestCoastProjects

Reputation: 63062

git push is not using the correct git configuration values

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

[user]
    name=sboesch
    email = [email protected]

Are they working? Seems so ..

$ git config user.email
[email protected]
[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 = [email protected]
        name = sboesch

Upvotes: 1

Views: 1447

Answers (2)

Chris Cassidy
Chris Cassidy

Reputation: 11

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 = [email protected]<your-username>:<company-repo-name>/spark.git
        fetch = +refs/heads/*:refs/remotes/origin/*

Upvotes: 0

torek
torek

Reputation: 488263

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.)

Upvotes: 1

Related Questions