Ankit
Ankit

Reputation: 491

How to change the default username of Git

When I'm trying to push my code using git push origin master it ask me the password for 'https://[email protected]' but my actual username is 'rest_ankit'.

I've used this command to change it 'git config --global user.name "rest_ankit"', but it didn't work. its still asking password for wrong username, and showing authentication failed. Plz help me out. Thanks.

Upvotes: 4

Views: 9843

Answers (2)

VonC
VonC

Reputation: 1329292

You can change the url of origin with:

git remote set-url https://[email protected]/username/reponame.git

That will change the username associated with the url as well.
Use the full url of your repo, not just bitbucket.org, but bitbucket.org/username/reponame.git, replacing username and reponame with the right values.


Note that the http credentials has nothing to do with git config user.name: the latter is user for commit authorship, not for authentication during push/pull.

Git 2.25.1 (Feb. 2020) clarifies the documentation on committer/author identities.

See commit 69e104d, commit 813f602, commit bc94e58 (22 Jan 2020) by brian m. carlson (bk2204).
(Merged by Junio C Hamano -- gitster -- in commit c9ccf9d, 30 Jan 2020)
Discussed here.

doc: provide guidance on user.name format

Signed-off-by: brian m. carlson

It's a frequent misconception that the user.name variable controls authentication in some way, and as a result, beginning users frequently attempt to change it when they're having authentication troubles.
Document that the convention is that this variable represents some form of a human's personal name, although that is not required.

In addition, address concerns about whether Unicode is supported.

Use the term "personal name" as this is likely to draw the intended contrast, be applicable across cultures which may have different naming conventions, and be easily understandable to people who do not speak English as their first language.

Indicate that "some form" is conventionally used, as people may use a nickname or preferred name instead of a full legal name.

Point users who may be confused about authentication to an appropriate configuration option instead.

Provide a shortened form of this information in the configuration option description.

so the git config user man page does explain that:

the name forms of these variables conventionally refer to some form of a personal name.

And git commit includes:

COMMIT INFORMATION

Author and committer information is taken from the following environment variables, if set:

GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL
GIT_AUTHOR_DATE
GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL
GIT_COMMITTER_DATE

(nb "<", ">" and "\n"s are stripped)

The author and committer names are by convention some form of a personal name (that is, the name by which other humans refer to you), although Git does not enforce or require any particular form.
Arbitrary Unicode may be used, subject to the constraints listed above.
This name has no effect on authentication; for that, see the credential.username variable, used in gitcredentials.

Upvotes: 4

edrich13
edrich13

Reputation: 829

ssh

git remote set-url origin [email protected]:{new team or account name}/{repository name}.git

https

git remote set-url origin https://{username}@bitbucket.org/{new team or account name}/{repository name}.git

then check the changes using

git remote -v

if u have problems while pushing and the remote of push has not changed then type

for ssh

git remote set-url --push origin [email protected]:{new team or account name}/{repository name}.git

for https

git remote set-url --push origin https://{username}@bitbucket.org/{new team or account name}/{repository name}.git

Upvotes: 4

Related Questions