-1

Here is the situation.

I have some git repositorys. Say the repository A and B that are both hosted on gitlab.com

I already did

git config --global user.name "MyCorrectUserName"

and I see, that it worked:

git config --global --list
user.name=MyCorrectUserName
user.email=my@gitlabmail.com
credential.helper=/usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring

In repository A I do some commit and so on and then do a git push origin master it asks for my password (so it knows my username. GREAT!)

In repository B I do the same and it asks for my username. Well.

in repository A/.git/config I see

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

in repository B/.git/config I see

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = https://gitlab.com/MyCorrectUserName/B
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[user]
    name = MyCorrectUserName

I tried to

Edit:

I tried to change the B repository's config as it is in A (username@gitlab.com). It did not work.

How can I get git to remember my username everywhere?

Martin
  • 659
  • 7
  • 14
  • 2
    I think you're a bit confused about what you're dealing with here. `git config --global user.name` is used to tell git your author name, used during commits. It is not used when pushing or fetching against remotes, for that you have credentials. Pay particular attention to the url here, your A repository shows "https:// **MyCorrectUserName@** .." whereas your B repository doesn't. – Lasse V. Karlsen May 19 '17 at 13:10
  • Yes, I saw that and I tried to change the B repository's config as it is in A (username@gitlab.com). It did not work. (What you suggest here, I intended to write in my opening post after "I tried to". Seems I got carried away.. sry – Martin May 23 '17 at 11:06

2 Answers2

1

@Lassy is right in the first comment. This has to do with the url parameter of the [remote "origin"] block in your config.

On repository A, your username is in the URL while it's not on B. Pay particular attention to the url here, your A repository shows "https:// MyCorrectUserName@ .." whereas your B repository doesn't.

You could correct the repository B url parameter this way:

git remote set-url origin https://MyCorrectUserName@gitlab.com/MyCorrectUserName/B

You could also simply edit the .git/config file of repository B and add the your username as stated above.

Also, You may prefer register a SSH key and use ssh protocol instead of http as described here. Since with a key, you don't have to deal with username anymore.

MensSana
  • 521
  • 1
  • 5
  • 16
-2

A better solution than using git's global username turned out to be using the gnome-keyring to remember my credentials.

I already installed and setup the gnome-keyring to work with git (as described here https://stackoverflow.com/a/13390889/2867993 ) but it only started working as soon as I started my x session with a display manager (I use lightdm now) instead of startx

Community
  • 1
  • 1
Martin
  • 659
  • 7
  • 14
  • So this is downvoted because it's not a solution that has anything to do with "global.username"? – Martin May 23 '17 at 11:08