转载自:  https://help.github.com/articles/caching-your-github-password-in-git/

 

If you're cloning GitHub repositories using HTTPS, you can use a credential helper to tell Git to remember your GitHub username and password every time it talks to GitHub.

If you clone GitHub repositories using SSH, then you authenticate using SSH keys instead of a username and password. For help setting up an SSH connection, see Generating SSH Keys.

Tips:

  • You need Git 1.7.10 or newer to use the credential helper.
  • If you installed Git using Homebrew, the osxkeychain helper may already be installed.

Install the osxkeychain credential helper and tell Git to use it.

  1. Find out if the osxkeychain credential helper is already installed by trying to run it:

    git credential-osxkeychain
    # Test for the cred helper
    Usage: git credential-osxkeychain <get|store|erase>
    
  2. If the osxkeychain helper isn't installed, download it with curl:

    git credential-osxkeychain
    # Test for the cred helper
    git: 'credential-osxkeychain' is not a git command. See 'git --help'.
    curl -s -O \
    https://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
    # Download the helper
    chmod u+x git-credential-osxkeychain
    # Fix the permissions on the file so it can be run
    
  3. Install the helper into the same directory where Git itself is installed:

    sudo mv git-credential-osxkeychain \
    "$(dirname $(which git))/git-credential-osxkeychain"
    # Move the helper to the path where git is installed
    Password: [enter your password]
    
  4. Tell Git to use osxkeychain using the global credential.helper config:

    git config --global credential.helper osxkeychain
    # Set git to use the osxkeychain credential helper
    

The next time you clone an HTTPS URL that requires a password, you'll be prompted for your username and password, and to grant access to the OSX keychain. After you've done this, the username and password are stored in your keychain and you won't be required to type them in to Git again.