mac下github的使用

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

//創(chuàng)建新的倉(cāng)庫(kù)


75A2B390401409B247E8864621CAA7E4.jpg

//填寫信息


F72EBD549D45BC254D287C3188C33719.jpg

//創(chuàng)建完成


D8757F55-3979-4038-A047-46E69C15ABDF.png

三,創(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:


1038D3987E832F6C511088405392EF91.jpg

四,在github上添加ssh


BE6A80897A435348070A466BF31A7262.jpg
68056767-0A70-4511-A0A2-84166E49B64D.png
49FE37F16C62E5BB3C426DB6E2D407BE.jpg

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

B6B0A30EABBB9C1FD5CC705C632A565C.jpg
image

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


9AF928D5495C83A968A4CDAA16BD2993.jpg

//然后可以在終端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)完成

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容