Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a default username for HTTPS git push?

Tags:

git

github

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?

like image 981
Jez Avatar asked Oct 18 '12 13:10

Jez


People also ask

How do I change the username when pushing to GitHub?

About Git usernames You can change the name that is associated with your Git commits using the git config command. The new name you set will be visible in any future commits you push to GitHub from the command line.

Does Git push use HTTPS?

You can only push to two types of URL addresses: An HTTPS URL like https://github.com/user/repo.git. An SSH URL, like [email protected]:user/repo.git.

What is GitHub HTTPS username?

Your user name is what immediately follows the https://github.com/ .


1 Answers

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.

like image 107
Jez Avatar answered Oct 30 '22 17:10

Jez