初始化Git
1. 安裝Git客戶端
[windows用戶請戳]:http://msysgit.github.com/](http://msysgit.github.com/
[mac用戶請戳]:http://code.google.com/p/tortoisegit/(http://code.google.com/p/tortoisegit
一路下一步下一步既可
2. 配置Git
1. 在電腦硬盤里找一塊地方存放本地倉庫,右鍵Git Bash進入git命令行
執行如下代碼 生成.git文件夾,表示本地git創建成功
git config --global user.name "littonishir"
git config --global user.email "littonishir@gmail.com"
git init
2. 配置ssh key
"你的郵箱" 然后一路回車,直到出現randomart image 既可
ssh-keygen -t rsa -C "littonishir@gmail.com"
cat 一下 把key 復制下來
cat /c/Users/yang/.ssh/id_rsa.pub
打開github,選擇Account Settings
左邊選擇SSH and GPG Keys,點擊New SSH key title不重要 將你復制的key粘貼進來 Add SSH Key既可
驗證是否成功
ssh -T git@github.com
回車就會看到:You’ve successfully authenticated, but GitHub does not provide shell access .這就表示已成功連上github.
代碼上傳到GitHub
1. 創建項目
1.點擊+號->new repository 填寫Repository的名字 填寫Repository的描述 (Initialize this repository with a README)可選
2.創建完成后點擊clone or download 復制Repository的地址
2. 本地初始化一個項目
1.git 的基礎配置,作用是告訴 git 你是誰
git config --global user.name "littonishir"
git config --global user.email "littonishir@gmail.com"
2.在你的需要初始化版本庫的文件夾中執行
git init
git remote add origin git@github.com:littonishir/hello.git
3.如果你想克隆一個項目,只需要執行(不是必須)
git clone git@github.com:littonishir/hello.git
3.完成第一次提交
1.進入你已經初始化好的或者克隆項目的目錄,然后執行
git pull origin master
git add .
2.若出現該warning: LF will be replaced by CRLF in xxx文件(解決辦法如下代碼)
git config --global core.autocrlf false //禁用自動轉換
3.提交信息
git commit -m "Initial commit"
4.正式上傳
git push origin master
至此代碼上傳完成
更新代碼到GitHub
1.正規方式
添加
git add 文件名
提交
git commit -m "update Readme.md"
推送
git push origin master
2.強制推送(路子比較野謹慎使用)
將本地更新的代碼push到遠程(如果普通的git push origin master提交不上,又不是協同開發,可以使用這個)
git push -u origin master -f