As developers, we often need to use git for version control. Usually we will push the code to the remote warehouse, and then we need to enter the username and password for verification. However, it is very troublesome to enter the username and password every time. Is there any way to simplify this process? This article will introduce how to set a git password locally to make your git use more convenient.
First you need to make sure you have installed git. If you have not installed it yet, you can go to the official website to download the installation package and install it: https://git-scm .com/download
Open the terminal and enter the command: Git Bash
Enter the following commands in the terminal to set the global user name and email:
$ git config --global user.name "Your Name" $ git config --global user.email "your.email@example.com"
If you have not generated an SSH key yet , you can skip this step. Otherwise, enter the following command in the terminal to generate the SSH key:
$ ssh-keygen -t rsa -C "your.email@example.com"
Enter the password as prompted, or just press Enter to skip the password setting.
In git, there are two ways to cache passwords locally: using git's credential helper, or using an SSH agent. Here we will introduce the first way.
Enter the following command in the terminal:
$ git config --global credential.helper cache
This will turn on password caching and set the default caching time to 15 minutes. If you need to customize the time, you can add parameters at the end, in seconds. For example, if it is set to 30 minutes, enter the following command:
$ git config --global credential.helper 'cache --timeout=1800'
Complete After the above settings, when you perform git operations again, you will see a prompt similar to the following:
$ git push Username for 'https://github.com': your_username Password for 'https://your_username@github.com':
At this time, you only need to enter the password once, and then git will cache the password. When you execute a similar command again, No need to enter password anymore.
If you want to clear the password cache, you can enter the following command:
$ git config --global --unset credential.helper
This will disable password caching.
Summary
Through the introduction of this article, you have learned how to set the git password locally to make your git use more convenient. Of course, to ensure account security, we do not recommend permanently saving passwords locally. If you are using a public computer, use caution.
The above is the detailed content of git local setting password. For more information, please follow other related articles on the PHP Chinese website!