一,mac下先下載git工具, 這里鏈接就不上了,可以自行百度然后安裝(windows的也可以下載),都是用終端命令,而不需要使用可視化工具操作.
二,在github上創(chuàng)建一個(gè)新的項(xiàng)目庫(kù), New Repository, 如下圖.
//創(chuàng)建新的倉(cāng)庫(kù)

//填寫信息

//創(chuàng)建完成

三,創(chuàng)建ssh
$ cd ~/.ssh若提示“-bash: cd: ~/.ssh: No such file or directory” 那就說(shuō)明.ssh文件夾不存在,那么則進(jìn)行下一個(gè)步驟,否則就是將原來(lái)的.ssh文件夾備份以下,亦或是切換到其他路徑下建立ssh.
也可以輸入ssh-keygen -t rsa -C 715446500@qq.com (這里的為你注冊(cè)Github時(shí)的郵箱賬號(hào)),然后執(zhí)行命令,創(chuàng)建ssh,執(zhí)行成功后會(huì)有以下提示
gebilaowang:~ a111$ cd /Users/a111/Desktop/project
gebilaowang:project a111$ git init
Initialized empty Git repository in /Users/a111/Desktop/project/.git/
gebilaowang:project a111$ ssh-keygen -t rsa -C715446500@qq.com
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/a111/.ssh/id_rsa): // .ssh默認(rèn)路徑,不輸入則不修改
Enter passphrase (empty for no passphrase):// 密碼長(zhǎng)度至少為4,否則失敗
Enter same passphrase again:
Your identification has been saved in /Users/yuyuhang/.ssh/id_rsa.
Your public key has been saved in /Users/yuyuhang/.ssh/id_rsa.pub.
出現(xiàn)以下內(nèi)容就是創(chuàng)建成功了
The key's randomart image is:

四,在github上添加ssh



然后打開剛才創(chuàng)建的ssh文件,這里去剛才默認(rèn)保存的地址去查找, 找到生成的id_rsa.pub文件(/User/yourname/.ssh.is_rsa.pub)用文本打開,copy其中的內(nèi)容

這串內(nèi)容是在github創(chuàng)建ssh的時(shí)候用到的,直接把內(nèi)容copy到key里就行

//然后可以在終端cd到你要存放代碼的本地文件目錄下
gebilaowang:~ a111$ ls
AFSCSJPro Music
Applications Pictures
Desktop Public
Documents README.md
Downloads oppaP2rVOPTehvvadG4rc32D2Eo44g.png
Library 商超世界logo16*16.png
Movies
gebilaowang:~ a111$ pwd
/Users/a111
gebilaowang:~ a111$ cd Users/a11/Desktop
-bash: cd: Users/a11/Desktop: No such file or directory
gebilaowang:~ a111$ cd /Users/a111/Desktop
gebilaowang:Desktop a111$ git init
Initialized empty Git repository in /Users/a111/Desktop/.git/
gebilaowang:Desktop a111$ cd /Users/a111/Desktop/github
然后要初始化git
gebilaowang:github a111$ git init
Initialized empty Git repository in /Users/a111/Desktop/github/.git/
然后add 添加文件到本地 并且 commit 提交到本地
add 其中add. 可以添加全部文件
gebilaowang:github a111$ git add AFYiTaoHuiPro
gebilaowang:github a111$ git add AFYiTaoHuiPro.xcodeproj
gebilaowang:github a111$ git add AFYiTaoHuiPro.xcworkspace
gebilaowang:github a111$ git add Podfile
gebilaowang:github a111$ git add Podfile.lock
gebilaowang:github a111$ git add Pods
gebilaowang:github a111$ git add README
commit
gebilaowang:github a111$ git commit -am'添加文件'
[master (root-commit) b2ea762] 添加文件
5856 files changed, 461875 insertions(+)
create mode 100644 AFYiTaoHuiPro.xcodeproj/project.pbxproj
create mode 100644 AFYiTaoHuiPro.xcodeproj/project.xcworkspace/contents.xcworkspacedata
然后添加遠(yuǎn)程倉(cāng)庫(kù)別名
gebilaowang:github a111$ git remote add origin git@github.com:xiaoyuanlizhi/SCSJNew.git
gebilaowang:github a111$ git remote -v
origin git@github.com:xiaoyuanlizhi/SCSJNew.git (fetch)
origin git@github.com:xiaoyuanlizhi/SCSJNew.git (push)
然后從遠(yuǎn)程分支拉流
//需要輸入剛才創(chuàng)建 ssh的時(shí)候的密碼
gebilaowang:github a111$ git pull origin master
Enter passphrase for key '/Users/a111/.ssh/id_rsa':
最后git push origin master
gebilaowang:github a111$ git push origin master
Enter passphrase for key '/Users/a111/.ssh/id_rsa':
Counting objects: 6304, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6183/6183), done.
Writing objects: 100% (6304/6304), 181.48 MiB | 424.00 KiB/s, done.
至此所有的git上傳過(guò)程已經(jīng)完成