Git-团队协作

团队内协作

Git-团队协作_第1张图片

准备工作

使用Github,两个账号:etaon和etaoner

本地:

alma—>etaon
worker-03—>etaoner

Github已经不使用用户名和密码方式:

Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

各自的ssh id_rsa.pub事先配置好,参考:

Connecting to GitHub with SSH - GitHub Docs

远程仓库操作

命令 作用
git remote -v 查看当前所有远程地址别名
git remote add 别名 远程地址 起别名
git push 别名 分支 推送本地分支上的内容到远程仓库
git clone 远程地址 将远程仓库的内容克隆到本地
git pull 远程库地址别名 远程分支名 将远程仓库对于分支最新内容拉下来后与当前本地分支直接合并

Alma:

[root@Alma ~]# mkdir git-demo
[root@Alma ~]# cd git-demo/
[root@Alma git-demo]# git init
Initialized empty Git repository in /root/git-demo/.git/
[root@Alma git-demo]# touch readme.md

[root@Alma git-demo]# echo '1st to readme~~~' > readme.md
[root@Alma git-demo]# cat readme.md 
1st to readme~~~
[root@Alma git-demo]# git add  .
[root@Alma git-demo]# git commit readme.md -m 'The 1st'
[master (root-commit) 10132b0] The 1st
 1 file changed, 1 insertion(+)
 create mode 100644 readme.md
[root@Alma git-demo]# git reflog
10132b0 (HEAD -> master) HEAD@{0}: commit (initial): The 1st
[root@Alma git-demo]# echo '2nd to readme~~~' >> readme.md
[root@Alma git-demo]# cat readme.md 
1st to readme~~~
2nd to readme~~~
[root@Alma git-demo]# git add  .
[root@Alma git-demo]# git commit readme.md -m 'The 2st'
[master f38edd1] The 2st
 1 file changed, 1 insertion(+)
[root@Alma git-demo]# git reflog
f38edd1 (HEAD -> master) HEAD@{0}: commit: The 2st
10132b0 HEAD@{1}: commit (initial): The 1st 

#现在readme.md的内容是下面部分

1st to readme~~~
2nd to readme~~~

在github中,用etaon账号建立仓库:git-demo

push内容到github

[root@Alma git-demo]# git branch -M main #创建分支(原有为master)
[root@Alma git-demo]# git checkout main #切换到main
Already on 'main'
[root@Alma git-demo]# git remote add git-demo https://github.com/etaon/git-demo.git#添加远程仓库,ssh方式
[root@Alma git-demo]# git remote -v#查看远程库
git-demo        [email protected]:etaon/git-demo.git (fetch)
git-demo        [email protected]:etaon/git-demo.git (push)
[root@Alma git-demo]# git branch -v#查看分支
* main f38edd1 The 2st
[root@Alma git-demo]# git push git-demo main#push到远程库
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 442 bytes | 442.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:etaon/git-demo.git
 * [new branch]      main -> main

在github使用etaon账户编辑readme.md

Git-团队协作_第2张图片

Alma pull:

[root@Alma git-demo]# git pull git-demo main
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:

  git config pull.rebase false  # merge (the default strategy)
  git config pull.rebase true   # rebase
  git config pull.ff only       # fast-forward only

You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.

remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 644 bytes | 20.00 KiB/s, done.
From github.com:etaon/git-demo
 * branch            main       -> FETCH_HEAD
   f38edd1..99033ea  main       -> git-demo/main
Updating f38edd1..99033ea
Fast-forward
 readme.md | 3 +++
 1 file changed, 3 insertions(+)
[root@Alma git-demo]# cat readme.md 
1st to readme~~~

2nd to readme~~~

2022-02-10

Worker-03:clone到本地git-demo库

[root@worker-03 ~]# git config --global user.name etaoner
[root@worker-03 ~]# git config --global user.email [email protected]
[root@worker-03 ~]# git clone https://github.com/etaon/git-demo.git
Cloning into 'git-demo'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 9 (delta 0), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), done.
[root@worker-03 ~]# cd git-demo/
[root@worker-03 git-demo]# ls
readme.md
[root@worker-03 git-demo]# cat readme.md 
1st to readme~~~

2nd to readme~~~

2022-02-10
[root@worker-03 git-demo]# git remote -v
**origin**  https://github.com/etaon/git-demo.git (fetch)
**origin**  https://github.com/etaon/git-demo.git (push)

clone 会做如下操作:

1、拉取代码
2、初始化本地仓库
3、创建别名-默认为origin

邀请合作者

etaon在github邀请合作者:etaoner

Git-团队协作_第3张图片

仓库—>Settings—>Collaborators—>Manage access—>Add people

复制Invite链接,发送给etaoner

合作者加入

合作者打开链接并选择同意

Git-团队协作_第4张图片

此时,在Worker-03上的修改可以push,(使用token登录的etaoner的账号)

[root@worker-03 git-demo]# git push [email protected]:etaon/git-demo.git
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
ECDSA key fingerprint is MD5:7b:99:81:1e:4c:91:a5:0d:5a:2e:2e:80:13:3f:24:ca.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes | 281.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:etaon/git-demo.git
   99033ea..3897420  main -> main

从etaon和etaoner的账户都可以看到push情况

Git-团队协作_第5张图片

Git-团队协作_第6张图片

注意:在etaoner的github账户中并没有仓库

Alma 本地库通过pull更新

[root@Alma git-demo]# git pull git-demo main
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:

  git config pull.rebase false  # merge (the default strategy)
  git config pull.rebase true   # rebase
  git config pull.ff only       # fast-forward only

You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.

remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 261 bytes | 261.00 KiB/s, done.
From github.com:etaon/git-demo
 * branch            main       -> FETCH_HEAD
   99033ea..3897420  main       -> git-demo/main
Updating 99033ea..3897420
Fast-forward
 readme.md | 2 ++
 1 file changed, 2 insertions(+)
[root@Alma git-demo]# cat readme.md 
1st to readme~~~

2nd to readme~~~

2022-02-10

change by etaoner

跨团队协作

使用另外一个账号joinini来表示团队外成员

Git-团队协作_第7张图片

fork仓库

Git-团队协作_第8张图片

可以看到:

在这里插入图片描述

joinini / git-demo -->名字

forked from etaon/git-demo -->来源

joinini在线编辑

Git-团队协作_第9张图片

提交:

Git-团队协作_第10张图片

创建一个pull request

Git-团队协作_第11张图片

提交以后:

在joinini账户中,发现转到etaon/git-demo
Git-团队协作_第12张图片

etaon账户的操作

在etaon的账户中可以看到pull request

Git-团队协作_第13张图片

进入request还可以发起聊天

Git-团队协作_第14张图片

Git-团队协作_第15张图片

joinini可以看到:

Git-团队协作_第16张图片

合并代码:

Git-团队协作_第17张图片

得到结果

Git-团队协作_第18张图片

etaon可以在alma上更新本地库

[root@Alma git-demo]# git pull git-demo main
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:

  git config pull.rebase false  # merge (the default strategy)
  git config pull.rebase true   # rebase
  git config pull.ff only       # fast-forward only

You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.

remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
Unpacking objects: 100% (4/4), 1.28 KiB | 1.28 MiB/s, done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
From github.com:etaon/git-demo
 * branch            main       -> FETCH_HEAD
   3897420..f34aef4  main       -> git-demo/main
Updating 3897420..f34aef4
Fast-forward
 readme.md | 2 ++
 1 file changed, 2 insertions(+)

[root@Alma git-demo]# cat readme.md 
1st to readme~~~

2nd to readme~~~

2022-02-10

change by etaoner

change by joinini, your friend

你可能感兴趣的:(git,github)