GIT快速入門

基本配置

下載軟件

git-scm

Git配置用戶名與郵箱

# 右鍵--Git Bash Here
git config --global user.name "gdxieyue"
git config --global user.email "[email protected]"
ssh-keygen -t rsa -C "[email protected]"
clip < ~/.ssh/id_rsa.pub

# windows路徑爲
C:\Users\your_username\.ssh
id_rsa.pub

配置公鑰

多賬戶配置(可跳過)

傳送門: 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 origin  myBranch

切換分支

  • 切換分支時,如果有未完成的工作,會帶到切換的分支。
    所以切換分支前,注意先 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

參考文章

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章