自學(xué)前端半年了,今天才對(duì)github的使用有了初步了解,于是根據(jù)自己的經(jīng)驗(yàn)總結(jié)了使用方法。
進(jìn)入 github 的網(wǎng)站 [https://github.com/] 注冊(cè)帳號(hào)。
下載安裝 git [https://git-scm.com/downloads] 。
打開(kāi)終端輸入
git --version指令可查看已安裝git的版本。查看.ssh: 在終端輸入指令
cd ~/.ssh。如果提示-bash:cd: ~/.ssh: No such file or directory,
說(shuō)明ssh不存在,則需要?jiǎng)?chuàng)建一個(gè)。在終端輸入指令ssh-keygen -t rsa -C email,email寫(xiě)注冊(cè)帳號(hào)時(shí)的郵箱地址。
回車之后會(huì)出現(xiàn)以下提示:
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):(此為默認(rèn)路徑,可不修改)
Created directory '/Users/username/.ssh'.
Enter passphrase (empty for no passphrase):(設(shè)置4位以上的密碼)
Enter same passphrase again:(再次輸入密碼以確認(rèn))
Your identification has been saved in /Users/username/.ssh/id_rsa回到github網(wǎng)站登錄帳號(hào),右上角用戶頭像點(diǎn)擊選擇 Settings,然后點(diǎn)擊左邊 Personal settings 一欄
中的 SSH and GPG keys,進(jìn)入之后選擇 New SSH key,然后填寫(xiě)Title和Key。
Title: 可填寫(xiě)注冊(cè)郵箱地址
Key: 進(jìn)入目錄 /User/username/.ssh/ 找到 is_rsa.pub,用文本編輯器打開(kāi),拷貝里面的內(nèi)容即可。(
打開(kāi)Finder使用快捷鍵Command + Shift + h 進(jìn)入用戶根目錄,再使用快捷鍵 Command + Shift + . 取消文
件隱藏即可找到is_rsa.pub文件)
最后點(diǎn)擊 Add SSH key。創(chuàng)建版本庫(kù),回到github個(gè)人主頁(yè),點(diǎn)擊位于中央的 Start a project, 在 Repository name 處輸入一
個(gè)版本庫(kù)名稱,點(diǎn)擊Create repository。成功創(chuàng)建版本庫(kù)之后,在終端使用“cd /文件夾路徑” 選擇你想建立本地版本庫(kù)的文件夾路徑,比如我的是項(xiàng)目是在桌面的
文件夾myGit,則輸入cd /Users/username/Desktop/myGit,然后按照github上新庫(kù)的提示 …or create a new
repository on the command line 依次輸入指令,比如我的是:
echo "# MonGit" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/username/myGit.git
git push -u origin master
然后會(huì)出現(xiàn)以下提示:
Username for 'https://github.com':(輸入github上的用戶名)
Password for 'https://username@github.com':(輸入github的登錄密碼)提交項(xiàng)目,打開(kāi)終端,同樣利用cd指令進(jìn)入本地倉(cāng)庫(kù),輸入:
git add 文件/文件夾路徑
git commit –m “你的注釋”
git push origin master
成功執(zhí)行后會(huì)顯示幾行數(shù)據(jù),最后以master -> master結(jié)束。