This study will briefly discuss the procedure of saving the username and password in Git.
How to Save Username and Password in Git?
As a Git user, you always have to provide your credentials for connecting a remote repository with Git’s local repository. To avoid this hassle, Git enables you to store a username and password locally and globally to be accessible to all current project users.
For the corresponding purpose, follow the below steps.
Step 1: Open GitHub Account
Firstly, open a browser, go to your “GitHub” repository where you want to save your username and password, and copy the repository “URL”. For instance, we will copy the link of our “test” remote repository from the address bar:
Step 2: Launch Git Bash
Search for the “Git Bash” with the help of the “Startup” menu and launch it:
Step 3: Clone Repository
Now, we will clone the selected remote Git repository and set a username and password to make things easier. To do so, we will execute the “git clone” command with copied remote repository URL as follows:
Here, we have specified “Linuxhint” as our username and “12345” as the password:
The below output indicates that the “test” remote repository is successfully cloned:
Step 4: Save Credentials
Next, run the following “git config” command to save the specified Git credentials in the “.git/config” file:
Above command will store our provided credentials in our local repository:
Next, we will add the “–global” option with the “git config” command to save the credential globally:
Step 5: Pull Request
Enter your username and password, which you have recently stored in the “~/.git-credential” file as plain text, in the case when you pull or push from the remote repository for the first time:
The output of the above-given command displayed “Already up to date” message because we have already saved the username and password in Git after cloning the repository:
If you have cloned the repository without setting the credentials, follow the below section to save your username and password.
How to Save Password and Username for Already Cloned repository?
If you have cloned a Git remote repository without configuring a username and password, Git bash enables you to update the “URL” and specify credentials with the help of the following command:
Here, we have specified “LinuxWorld” as our username, “09876” as its password, and specified the link of the cloned repository after the “@” sign.
After executing the above-given command, perform the same steps for saving the credentials we already provided in the first section.
Conclusion
To save username and password in Git, open your “GitHub” remote repository and copy its “URL”. Then, launch “Git Bash”, paste the “URL” with the “$ git clone” command, specify the credential and execute it. Lastly, run the “$ git config –global credential.helper store” command to save the credential in the “.git/config” file. This study demonstrated the procedure for saving a username and password in Git.