/**To use this option, you need to tur
*n on the credential helper so that git
*will save your password in memory f*or some time:
*/
git config --global credential.helper cache
# Set git to use the credential memory cache
//By default git will cache your password for 15 minutes. You can change this if you like.
git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)
4,配置远程github库ssh密码
First, we need to check for existing ssh keys on your computer. Open up Git Bash and run:
cd ~/.ssh
# Checks to see if there is a directory named ".ssh" in your user directory
Since there is already an SSH directory you'll want to back the old one up and remove it:
ls
# Lists all the subdirectories in the current directory
# config id_rsa id_rsa.pub known_hosts
mkdir key_backup
# Makes a subdirectory called "key_backup" in the current directory
cp id_rsa* key_backup
# Copies the id_rsa keypair into key_backup
rm id_rsa*
# Deletes the id_rsa keypair
To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.
ssh-keygen -t rsa -C "your_email@youremail.com"
# Creates a new ssh key using the provided email
# Generating public/private rsa key pair.
# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]
Now you need to enter a passphrase.
Why do passphrases matter?
# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
Which should give you something like this:
# Your identification has been saved in /c/Users/you/.ssh/id_rsa.
# Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@youremail.com
Step 4: Add your SSH key to GitHub
Run the following code to copy the key to your clipboard.
clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
Be warned: it is important to copy the key exactly without adding newlines or whitespace. Thankfully the clip command makes it easy to perform this setup perfectly.
Go to your Account Settings
Click "SSH Keys" in the left sidebar
Click "Add SSH key"
Paste your key into the "Key" field
Click "Add key"
Confirm the action by entering your GitHub password
5,建立一个本地代码库
Step 1: Create the README file
In the prompt, type the following code:
mkdir ~/Hello-World
# Creates a directory for your project called "Hello-World" in your user directory
cd ~/Hello-World
# Changes the current working directory to your newly created directory
git init
# Sets up the necessary Git files
# Initialized empty Git repository in /Users/you/Hello-World/.git/
touch README
# Creates a file called "README" in your Hello-World directory
Step 2: Commit your README
Now that you have your README set up, it's time to commit it. A commit is essentially a snapshot of all the files in your project at a particular point in time. In the prompt, type the following code:
More about commits
git add README
# Stages your README file, adding it to the list of files to be committed
git commit -m 'first commit'
# Commits your files, adding the message "first commit"
Step 3: Push your commit
So far everything you've done has been in your local repository, meaning you still haven't done anything on GitHub yet. To connect your local repository to your GitHub account, you will need to set a remote for your repo and push your commits to it:
More about remotes
git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repo
git push origin master
# Sends your commits in the "master" branch to GitHub