天天看點

github管理開發代碼流程

首先。通過github網站建立一個倉庫,得到倉庫位址

https://github.com/piercalex/a.git      

接着回到用戶端,打開git shell:

//在用戶端配置賬戶資訊
git config --global user.name 'piercalex' //設定初始賬号id
git config --global user.email '[email protected]' //設定郵箱
//在本地建立自己的版本倉庫
cd d: //我把版本倉庫建立在D盤,切換到D盤目錄
mkdir a //建立檔案夾,注意本地倉庫名要和git上建立的倉庫名一緻
cd a //進入a目錄
git init //初始化版本倉庫
touch README //建立一個README檔案,之後編輯README
git add README //将檔案添加到上傳隊列
git commit -m 'information' //送出
git remote add origin https://github.com/piercalex/a.git //遠端位址
//如果這裡有錯,錯誤資訊為fatal: remote origin already exists時,請輸入:git remote rm origin,然後繼續輸入上面那行繼續走流程。
git push origin master //上傳到遠端版本庫。輸入github郵箱和密碼
      

ok,已經完成github線上建立倉庫和線下倉庫關聯。

建立遠端分支,分賬号先登入git config設定完畢,去github頁面上找到源目錄,fork先。

git clone https://github.com/piercalex/a.git //克隆,并在本地目錄自動建立本地倉庫
cd a
git checkout -b dev //建立并切換到dev分支
git push --set-upstream origin dev //向主分支送出建立分支資訊
//輸入主分支郵箱和密碼,通過。遠端分支建立完畢
//編輯内容
git add .
git commit -m 'add dev' //彙總目錄
git push //送出
      

遠端分支工作完畢,回到master工作環境:

git checkout master
git merge dev --no-ff //merge合并工作先
git pull origin dev //從dev分支拉回較新代碼
git push //更新至master賬号下面,共其他分支pull
      

當出現以下錯誤時:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
      

解決辦法:

ls -al ~/.ssh //check for SSH keys
ssh-keygen -t rsa -C "[email protected]" //generate a new SSH keys
//enter後,輸入兩次passphrase,之後生成了SSH key
pbcopy < ~/.ssh/id_rsa.pub //拷貝公有秘鑰,到github上"add SSH key"
ssh -T [email protected] //輸入passphrase後連接配接成功!
      

  

SSH keys已經添加的情況下,git每次送出都需要輸入賬号密碼的解決辦法:(所使用的git位址是https服務,需要修改ssh服務)

git remote -v //查詢連結方式
# origin https://github.com/USERNAME/REPOSITORY.git(fetch)
# origin https://github.com/USERNAME/REPOSITORY.git(push)

git remote set-url origin [email protected]:USERNAME/REPOSITORY.git

git remote -v //再次執行查詢
# origin [email protected]:USERNAME/REPOSITORY.git(fetch)
# origin [email protected]:USERNAME/REPOSITORY.git(push)
      

 Git Bash中輸入中文不能正确顯示,而是變成Unicode時

git config --global core.quotepath false
      

Git忽略已存在的檔案,先.ignore添加内容,然後

git rm --cached logs/xx.log
      

Git mergetool不再生成煩人的備份檔案(*.orig)

git config --global mergetool.keepBackup false
      

The file will have its original line endings inyour working directory.//當報這個警告時是由于檔案夾遠端不存在,但是不影響送出

git config --global core.autocrlf false
      
git