1,注冊一個GitHub賬戶,登陸GitHub賬戶,添加一個儲存庫
2,進入Ubuntu命令窗口,創建文件夾。如 mkdir git
echo "# first_git" >> README.md git init git add README.md git commit -m "first commit" git remote add origin git@github.com:XXXXX/demo.git // xxx 換成自己名字 git push -u origin master
遇到問題1
5,*** Please tell me who you are. 6,Run 7, git config --global user.email "you@example.com" 8, git config --global user.name "Your Name" 9, 10,to set your account's default identity.
解決方法:設置郵箱地址和姓名
git config --global user.email “your_email@email.com“ // your_email@email.com 換成自己的郵箱 git config --global user.name "your name" // youname 換成自己的英文名字 然后按回車
再次連接
git remote add origin git@github.com:XXXXX/XXXX // 自己上一步設置的郵箱用戶名
git push -u origin master
遇到問題2,沒有權限
解決方法:
設置 SSH Key
ssh-keygen -t rsa -C “your_email@email.com” // 自己的郵箱
顯示
Generating public/private rsa key pair. Enter file in which to save the key (/Users/XXX/.ssh/id_rsa): // id_rsa的路徑 下一步有用 按回車 輸入密碼 再次輸入密碼
復制 id_rsa 密鑰
cat /home/XXX /.ssh/id_rsa.pub
回到GitHub中添加公開密鑰
點擊右上角的Settings,選擇SSH and GPG keys菜單,點擊 New SSH key
驗證是否成功
ssh -T git@github.com
顯示 Hi tianqixin! You've successfully authenticated, but GitHub does not provide shell access.
添加完成后,回到Ubuntu命令窗口
運行
git push -u origin master
成功了,
在github添加文件,可以git pull 到本地,本地可以git push 。。。。。。