How to Push Username in Git

Abdul Jabbar Feb 02, 2024
  1. Push Username in Git
  2. Update URL of Origin Remote Using SSH in Git
  3. Store Git Credentials
How to Push Username in Git

We will briefly discuss how to push usernames in Git in this article.

Push Username in Git

When we work with Git, it uses a username to recognize commits for its identity for the user. The username used in Git is not the same as that we use for our GitHub account, but it is different from the main account’s username.

We can change the username linked with our commits to the remote repository, which can be performed through the command git config using the command line in Git. We can set our new username applicable to our future commits that we push to or pull from Git using different commands.

Even after configuring the new username, we face some problems related to usernames and passwords in the future. Git keeps on asking those every time we interact with Git when we push some work to the remote repository.

This occurs when we use HTTPS URL for cloning for our repositories. Rather than using HTTPS, we will use the SSH.

This problem can be fixed by configuring Git to reserve passwords for us.

Update URL of Origin Remote Using SSH in Git

Use the following command to change a remote repository’s URL.

Command:

git remote set-url origin git@github.com:username/repo.git

Store Git Credentials

The following command in Git will store the username and password that will never be asked again in the future when we do the pull from the remote repository or push the latest work to the remote repository.

Command:

git config --global credential. helper store

This next command is for saving them for a session, or we can cache it for some time in the temporary storage.

Command:

git config --global credential. helper cache

Lastly, this command sets a timeout for the setting mentioned above to store it for some specific time in the local storage, and once the time is completed, it will be removed permanently.

Command:

git config --global credential. helper 'cache --timeout=600'
Author: Abdul Jabbar
Abdul Jabbar avatar Abdul Jabbar avatar

Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.

LinkedIn

Related Article - Git Push