1.註冊賬戶以及建立倉庫
要想使用github第一步當然是註冊github賬號了。之後就可以建立倉庫了(免費使用者只能建公共倉庫),create a new repository,填好名稱後create
2.安裝客戶端git
github是服務端,要想在自己電腦上使用git我們還需要乙個git客戶端, 在本地倉庫選擇git init here 會多出乙個 .git資料夾,右鍵git bash進入git命令列,為了把本地的倉庫傳到github,還需要配置ssh key
3.配置git
(1) 首先在本地建立ssh key;
$ ssh-keygen -t rsa -c 「your_email@youremail.com」 注意ssh-keygen命令中間沒有空格,如果在ssh後面加上空格, 會得到bad escape character 『ygen』.的錯誤。 後面的your_email@youremail.com改為你的郵箱,之後會要求確認路徑和輸入密碼, 我們這使用預設的一路回車就行。 成功的話會在~/下生成.ssh資料夾,進去,開啟id_rsa.pub,複製裡面的key。 回到github,進入account settings,左邊選擇ssh keys,add ssh key,title隨便填,貼上key。
(2) 為了驗證是否成功,在git bash下輸入: $ ssh -t git@github.com
如果是第一次的會提示是否continue,輸入yes就會看到:you』ve successfully authenticated, but github does not provide shell access 。這就表示已成功連上github。
(3) 接下來我們要做的就是把本地倉庫傳到github上去,在此之前還需要設定username和email,因為github每次commit都會記錄他們。
gitconfig−−globaluser.name」yourname」 git config –global user.email 「your_email@youremail.com」
4. 提交上傳
(1) 接下來在本地倉庫裡新增一些檔案,比如readme,
gitaddreadme git add readmegi
tcom
mit−
m「fi
rstc
ommi
t」(2
)上傳到
gith
ub: git
comm
it−m
「fir
stco
mmit
」(2)
上傳到g
ithu
b:
git push origin master
git push命令會將本地倉庫推送到遠端伺服器。
git pull命令則相反。
修改完**後,使用git status可以檢視檔案的差別,使用git add 新增要commit的檔案,也可以用git add -i來智慧型新增檔案。之後git commit提交本次修改,git push上傳到github。
5.一些常見錯誤
我用git add file新增檔案時出現這樣錯誤:
fatal: not a git repository (or any of the parent directories): .git
提示說沒有.git這樣乙個目錄,解決辦法如下:
git init就可以了!
推送本地庫到遠端庫的命令:
git push origin master origin/mast
git與github連線使用
上面命令表示,將當前分支推送到origin主機的對應分支。如果當前分支只有乙個追蹤分支,那麼主機名都可以省略。git push 如果當前分支與多個主機存在追蹤關係,那麼這個時候 u選項會指定乙個預設主機,這樣後面就可以不加任何引數使用git push。git push u origin master...
如何將本地git與github建立連線
將git與github聯絡起來,註冊github 查詢本地的ssh秘鑰,git裡面輸入ssh keygen 找到路徑後進入找到id rsa.pub 複製 回到github 右上角個人資訊 setting 左側ssh and gpg key 填寫ssh keys 1 檢查git與github是否已連線...
初次用Git 連線github基於window
記載一下我的從桌面連線github的基本步驟 github的連線 在使用雲端ide師預設自帶git,不用再安裝 但是筆者在自己win10的膝上型電腦配置環境 因此首先先裝乙個git for windows的 首先設定全域性的使用者名稱和你的郵箱 git config global user.name...