1. GitHub长途库房同步ssh协议配置
# 检查是否存在ssh公私钥
ls ~/.ssh
# 生成ssh公私钥
ssh-keygen -t ed25519 -C "your_email@example.com"
# 后边能够一路回车,不用做额外的处理
ls ~/.ssh
# id_ed25519.pub是公钥。公钥能够放到公网上面去。
# id_ed25519是私钥。私钥能够留在本地。
id_ed25519 id_ed25519.pub
GitHub->setting->SSH and GPG keys->New SSH key增加上面的公钥即可。一个账户能够配置多个这样的公钥。
运用公私钥的好处是运用push的时分不再需求用户名和密码。
2. 安排成员办理
能够经过Github username,邮件等办法约请他人加入安排。安排内部能够创立多个库房以及博客。 当然关于安排成员能够进行权限的办理,关于一个库房,安排办理员能够在库房Settings里的Member privileges对成员权限进行设置。
在安排中能够创立团队,默许安排内的成员有自行创立团队的权限。办理员也能够针对团队权限进行控制。
3. 分支的merge规则设置
关于feature以及其他的变更,需求经过pull request的办法提交。在进行merge的时分需求至少两人的code review。以便对master分支做保护。
4. 本地开发环境同步到远端库房
# git库房有3个效果域:local、global、system三个效果域
# 常用的体系账户能够设置global,将user.name和user.email与GitHub账户同步,system慎用(需求办理员权限)
git config --global user.email ${your_email_name}
git config --global user.name ${your_nick_name}
# 检查global效果域配置
git config --global --list
# 将git库房备份到本地
git clone git@github.com:QingxunVectory/IntegrationMerge.git code01
cd code01/
办法1
# 检查当时库房的一切分支
git branch -av
# 创立一个本地同名分支 feature/cpp
git checkout -b feature/cpp
vi hello.cpp
git add hello.cpp
git commit -m 'Add hello.cpp'
# 这里会报错
git push origin
# 让本地实质与长途的同名分支树立相关,并提交commit
git push --set-upstream origin feature/cpp
办法2
# 当时分支feature/go相关远端分支origin/feature/go;在运用push的时分直接push到远端的库房
git checkout -b feature/go origin/feature/go
git branch -av
vi hellworld.go
git add hellworld.go
git commit -m 'Add helloworld.go'
git push
5. GitHub Pull Request
在提交的时分能够选择reviewer,进行code review,届时reviewer会收到review恳求的邮件。
6. GitHub Code Review
reviewer能够经过Github面板对Pull Request提出建议,Review以邮件的办法回馈给submiter。
承认兼并分支后绿色的Fork标识会变成紫色。
7. 多用户访问远端分支
在库房的feature/go下做实验:
模仿用户1:
vi hellworld.go
git add hellworld.go
git commit -m'Modify helloworld.go by user1'
git push
模仿用户2:
git clone git@github.com:QingxunVectory/IntegrationMerge.git code02
git config --local user.email ${user2_email}
git checkout -b feature/go origin/feature/go
vi hellworld.go
git add hellworld.go
git commit -m'Modify helloworld.go by user2'
git push
错误提示:
To github.com:QingxunVectory/IntegrationMerge.git
! [rejected] feature/go -> feature/go (fetch first)
error: failed to push some refs to 'git@github.com:QingxunVectory/IntegrationMerge.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
呈现抵触,原因是现在对错fast_forward的状态。
# 下载分支的最新版别
git fetch
# 检查一切的branch
git branch -avv
* feature/go ec9bc81 [origin/feature/go: ahead 1, behind 1] Modify helloworld.go by user2
master a24ff7a [origin/master] Initial commit
remotes/origin/HEAD -> origin/master
remotes/origin/feature/cpp 5d8ea5b Add hello.cpp
remotes/origin/feature/go 79a6974 Modify helloworld.go by user1
remotes/origin/master a24ff7a Initial commit
ahead 1表明本地有一个commit没有提交到远端分支,behind 1表明远端分支有一个commit没有merge到本地。
处理办法:
# 相当于git fetch + git merge
git pull
Auto-merging hellworld.go
CONFLICT (content): Merge conflict in hellworld.go
Automatic merge failed; fix conflicts and then commit the result.
git pull失利,原因是咱们修正的是同一行代码。
# 修订最终版别
vi hellworld.go
# 这里要注意分支的状态
git status
On branch feature/go
Your branch and 'origin/feature/go' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: hellworld.go
no changes added to commit (use "git add" and/or "git commit -a")
# 咱们要经过git add的办法去提交merge后的commit
git commit -am 'Merge hellworld.go'
git push
建议在每次开发之前要更新当时特性分支
git fetch/pull
8. 用issue盯梢需求和BUG
在Settings的Features设置issue的模板。
在项目issue中提交,能够将issue指派给某个人,能够设置issue的标签。在issue栏目中能够对既有的issue进行过滤筛选。
9. 用projects办理issue即盯梢进展
在Projects新建Project(一个库房能够增加多个project),有几个模板可供选择。创立好Project之后,能够经过Add Card的办法增加需求对应的任务,把它们增加到to do list里边,进而对issue、pull request以及其他任务进行盯梢办理。
10. 特性分支向master分支兼并
在进行特性分支向master分支兼并,有3个选项:
merge commit
将屡次commit作为一个整体merge到master分支中去,相当于只处理一次抵触。
咱们用merge commit的办法将feature/go分支merge到master分支,检查一下分支的情况:
git fetch
git log --graph origin/master
* commit 66acfb8d4abdb2b179d558437f6c9e36776f253b (origin/master, origin/HEAD)
|\ Merge: a24ff7a 97ef0f2
| | Author: etc <72735722+rucetc@users.noreply.github.com>
| | Date: Tue Jun 7 01:19:31 2022 +0800
| |
| | Merge pull request #2 from QingxunVectory/feature/go
| |
| | Add helloworld.go
| |
| * commit 97ef0f26b19f96d7a747f98c657a2dcfa2506dd9 (HEAD -> feature/go, origin/feature/go)
| |\ Merge: ec9bc81 79a6974
| | | Author: rucetc <xzang2014@163.com>
| | | Date: Tue Jun 7 00:23:06 2022 +0800
| | |
| | | Merge hellworld.go
| | |
| | * commit 79a697436444406e3f4537ea59de87d74d5da5dd
| | | Author: rucetc <11840928@qq.com>
| | | Date: Mon Jun 6 23:53:21 2022 +0800
| | |
| | | Modify helloworld.go by user1
| | |
| * | commit ec9bc8198b6ab7c6271868ed24359e01f2cb0de4
| |/ Author: rucetc <xzang2014@163.com>
| | Date: Mon Jun 6 23:53:50 2022 +0800
| |
| | Modify helloworld.go by user2
| |
| * commit 5a6379848e90951c10c3801fbc994ff61b38e56d
|/ Author: rucetc <11840928@qq.com>
| Date: Mon Jun 6 21:54:46 2022 +0800
|
| Add helloworld.go
|
* commit a24ff7a0be44bbb9d29799d8ec370ba5e5c26942 (master)
Author: etc <72735722+rucetc@users.noreply.github.com>
Date: Mon Jun 6 18:12:55 2022 +0800
Initial commit
GitHub供给可视化的分支检查Insights下的Network
同理,咱们将特性分支feature/cpp也merge进master傍边,在看一下分支的情况:
假如projects应用的模板是主动办理kanban,当咱们完成将特性分支merge到master分支后,projects对应的pull request会主动切换成Done的状态。
squash and merge
在master分支上新生成commit,这个commit包含了特性分支里多个commit触及的文件变更。特点是在进行merge的时分并不会影响特性分支。
咱们检查一下分支情况:
rebase and merge
经过rebase的办法进行兼并,即对master分支进行变基,将特性分支的commit”仿制“到master分支上。
在兼并feature/go的时分呈现抵触了。
第一种处理方案
依据提示信息运用命令行处理抵触。处理抵触之后Merge图标的颜色由绿色变成紫色。
检查一下兼并后的分支情况:
第二种处理方案
在本地恢复环境,切换到feature/go分支
# 在远端master分支上做rebase处理,也就是在远端master上
git rebase origin/master
会提示咱们呈现抵触:
First, rewinding head to replay your work on top of it...
Applying: Add helloworld.go
Applying: Modify helloworld.go by user2
Applying: Modify helloworld.go by user1
Using index info to reconstruct a base tree...
M hellworld.go
Falling back to patching base and 3-way merge...
Auto-merging hellworld.go
CONFLICT (content): Merge conflict in hellworld.go
error: Failed to merge in the changes.
Patch failed at 0003 Modify helloworld.go by user1
hint: Use 'git am --show-current-patch' to see the failed patch
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
依照提示处理:
# 修正抵触文件
vi hellworld.go
# 将修正后的抵触文件重新加回暂存区
git add hellworld.go
git rebase --continue
# 检查分支变化
# 远端的feature/go分支经过变基的办法进行了merge。
git branch -avv
# push到远端的feature/go分支
git push origin feature/go
* feature/go dde383b [origin/feature/go: ahead 3, behind 4] Modify helloworld.go by user1
master a24ff7a [origin/master] Initial commit
remotes/origin/HEAD -> origin/master
remotes/origin/feature/cpp 5d8ea5b Add hello.cpp
remotes/origin/feature/go 97ef0f2 Merge hellworld.go
remotes/origin/master a24ff7a Initial commit
检查一下feature/go的变化:
对feature/go变完基之后,能够运用rebase and merge的办法兼并到master分支去了。
再将feature/cpp兼并到master分支之后,再看一下分支的情况:
两个特性分支现已经过变基的办法兼并到master分支上了。