首先在本地創建ssh key;
1
|
$ssh-keygen-t rsa -C "[email protected]"
|
後面的[email protected]改爲你的郵箱,之後會要求確認路徑和輸入密碼,我們這使用默認的一路回車就行。成功的話會在~/下生成.ssh文件夾,進去,打開id_rsa.pub,複製裏面的key。
回到github,進入Account Settings,左邊選擇SSH Keys,Add SSH Key,title隨便填,粘貼key。爲了驗證是否成功,在git bash下輸入:
1
|
$ssh-T [email protected]
|
如果是第一次的會提示是否continue,輸入yes就會看到:You’ve successfully authenticated, but GitHub does not provide shell access 。這就表示已成功連上github。
接下來我們要做的就是把本地倉庫傳到github上去,在此之前還需要設置username和email,因爲github每次commit都會記錄他們。
1
2
|
$ git config --global user.name "your name"
$ git config --global user.email "[email protected]"
|
Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/username/mygitrep.git
git push -u origin master
Push an existing repository from the command line
git remote add origin https://github.com/username/mygitrep.git
git push -u origin master