GIT快速入門
基本配置
下載軟體
Git配置使用者名稱與郵箱
# 右鍵--Git Bash Here git config --global user.name "gdxieyue" git config --global user.email "gdxieyue@gmail.com" ssh-keygen -t rsa -C "gdxieyue@gmail.com" clip < ~/.ssh/id_rsa.pub # windows路徑為 C:\Users\your_username\.ssh id_rsa.pub
配置公鑰

git公鑰配置.png
多賬戶配置(可跳過)
傳送門: Windows下Git多賬號配置,同一電腦多個ssh-key的管理
# 配置gitee Host gitee.com HostName gitee.com IdentityFile /home/gdtel/.ssh/gitee PreferredAuthentications publickey User gdxieyue # 配置辦公室 132.97.8.10 Host 132.97.8.10 HostName 132.97.8.10 IdentityFile /home/gdtel/.ssh/id_rsa PreferredAuthentications publickey User gdxieyue
Git的使用姿勢
master主分支(穩定版),develop為開發分支(開發版)。develop測試穩定後,合併到master分支。
分支操作
檢視所有分支
git branch -a
下載遠端分支到本地
#git上已經有master分支 和develop分支 #在本地,新建並切換到本地develop分支 git checkout -b develop #本地分支與遠端分支相關聯 git pull origin develop #簡單命令 git checkout -b develop origin/develop
新建本地分支
git checkout -b myBranch
刪除本地分支
git branch -d localBranch
提交本地分支到遠端
git checkout myBranch git push originmyBranch
切換分支
-
切換分支時,如果有未完成的工作,會帶到切換的分支。
所以切換分支前,注意先 git status 檢視狀態,git stash 快取,再切換過去。
git status #如果有未commit的操作,先git commit,或者git stash 暫存起來,再切換分支 git stash git checkout master
將Develop分支釋出到Master分支的命令
# 切換到Master分支 git checkout master # 對Develop分支進行合併 git merge --no-ff develop
git pull時提示衝突
#先暫存當前修改的程式碼 git stash #拉服務端程式碼 git pull # 放出之前的暫存的程式碼 git stash pop # 進行合併和提交
重新命名本地分支
git branch -m oldName newName