2015年末開始學習Python,接觸了git這個東西,會基礎的使用,順便在github上註冊了帳號 https://github.com/haoxrgit
今天從新整理一下配置使用的整個流程github
1 github註冊帳號shell
2 本地安裝gitdom
sudo apt-get update sudo apt-get install git
git官網下載地址:https://git-scm.com/downloadsssh
3 初始化目錄 在須要git的目錄下打開終端ide
git init
這樣就在本地創建了git倉庫。能夠直接操做git其餘命令。學習
在創建本地庫與github關聯以前,咱們須要作一些配置工做fetch
4 建立SSH Keyurl
在用戶主目錄下,看看有沒有.ssh目錄,若是有,再看看這個目錄下有沒有id_rsa
和id_rsa.pub
這兩個文件,若是已經有了,可直接跳到下一步。
若是沒有,打開Shell(Windows下打開Git Bash),建立SSH Key:郵箱地址爲github郵箱地址
ssh-keygen -t rsa -C "youremail@example.com"
把id_rsa.pub內容添加到github的SSH keys頁面。
5 驗證是否鏈接成功
ssh -T git@github.com
成功結果爲:
Hi haoxr! You've successfully authenticated, but GitHub does not provide shell access.
若是出現 Permission denied (publickey). 錯誤,參考:https://help.github.com/articles/error-permission-denied-publickey/
eval "$(ssh-agent -s)"
ssh-add
SSH警告
第一次使用Git的clone
或者push
命令鏈接GitHub時,會獲得一個警告,輸入yes
回車便可。
The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established. RSA key fingerprint is xx.xx.xx.xx.xx. Are you sure you want to continue connecting (yes/no)?
6 本地配置github
git config --global user.name "Your Name" git config --global user.email "youremail@domain.com"
查看配置信息
git config --list
7 本地庫與github關聯
git remote add origin git@github.com:haoxr/-faceDetection.git
git@github.com:haoxr/-faceDetection.git 能夠在你項目中去複製
關聯後能夠在.git目錄下的config文件中查看結果:
[remote "origin"] url = git@github.com:haoxr/-faceDetection.git fetch = +refs/heads/*:refs/remotes/origin/*
可能會出現 the repository exists. 提示,表示你重複關聯了,若是須要重置,能夠直接在以上文件中刪掉,也能夠命令:
git remote rm origin
再從新關聯
8 添加全部文件
git add .
9 提交到本地庫
git commit -m 提交內容說明
10 提交到遠程庫
git push -u origin master
第一次推送master
分支時,加上了-u
參數,Git不但會把本地的master
分支內容推送的遠程新的master
分支,還會把本地的master
分支和遠程的master
分支關聯起來,
在之後的推送或者拉取時就能夠簡化命令,只要本地做了提交,就能夠經過命令把本地master
分支的最新修改推送至GitHub
git push origin master
提交的文件有大小限制,注意大文件的移除和備份。
github的分支以及不少操做就不說了,須要用到的網上搜便可。