How to set a default username for HTTPS git push?
Asked Answered
E

2

9

I want to push to my remote repo, which is hosted on github, using HTTPS. No, I don't want to use SSH or any other protocol so please don't suggest that.

Now, I know you can specify a default username in the remote itself, like so:

git remote add origin https://[Username]@github.com/[OrgName]/[RepoName].git

However, considering the default HTTPS URL github gives does not contain a username, that would presumably mean every developer would need to manually modify the remote URL to add their username. Isn't there some global config setting you can use to just tell git your default push username? If not, why does github not give you an HTTPS remote URL that contains the [Username]@ part?

Ellswerth answered 18/10, 2012 at 13:27 Comment(0)
E
13

OK, git credentials can do this. Adding this to my git config fixed the problem:

[credential "https://github.com"]
    username = (MyUsername)

Note that git credentials is a relatively new feature in git, released in 1.7.9 or something, so it won't work in older versions.

Ellswerth answered 18/10, 2012 at 14:19 Comment(2)
To avoid manually changing the config, you could put some of this in your git configuration: git-scm.com/docs/git-config#Documentation/… resp. git-scm.com/docs/gitcredentialsFool
You could also use the git credential command in combination with a credential helper, but I for one haven't figured this out, yetFool
S
0
git config --global credential."https://github.com".username YourUserHere
Sillimanite answered 1/8 at 17:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.