github文档库: https://help.github.com/articles/
(一) 安装配置git
1. 安装git
2. username:显示在commit历史中,标识提交者
$ git config --global user.name "Your Name Here"
# Sets the default name for git to use when you commit
3. email:保存在commit中,github通过该email关联到github账户
$ git config --global user.email "your_email@example.com"
# Sets the default email for git to use when you commit
4. 使用password caching,仅对git version > 1.7.10有效
在一定时间内,不用每次输入password
默认缓存15分钟
$ git config --global credential.helper cache
# Set git to use the credential memory cache
改变缓存时间,单位为秒
$ git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)
(二) 创建repository
1. github上点击“new repository”
2. 在本地添加文件,以README为例
$ 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
# 创建README,向其添加内容
3. commit 所做改动
$ git add README
# Stages your README file, adding it to the list of files to be committed
$ git commit -m 'first commit'
# -m内容进入commit历史,可用git log查看
4. 推送到远端git库
$ git remote add origin https://github.com/username/Hello-World.git
# “username”为github用户名
# 禁止https访问时,可用http代替
$ git push origin master
# Sends your commits in the "master" branch to GitHub
5. 用git clone验证推送是否成功
$ mkdir ~/test_push
$ cd ~/test_push
$ git clone https://github.com/username/Hello-World.git