学习
路无止境!

没有伞的孩子要学会努力奔跑!


  • 首页

  • 归档

  • 关于我

  • 公益404

  • 搜索

Git-团队协作

团队内协作

Untitled

准备工作

使用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的内容是粗体部分**

在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        git@github.com:etaon/git-demo.git (fetch)
git-demo        git@github.com: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

Untitled

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

[root@worker-03 ~]# git config --global user.name etaoner
[root@worker-03 ~]# git config --global user.email etaoner@163.com
[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

Untitled

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

复制Invite链接,发送给etaoner

合作者加入

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

Untitled

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

[root@worker-03 git-demo]# git push git@github.com: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情况

Untitled

Untitled

注意:在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来表示团队外成员

Untitled

fork仓库

Untitled

可以看到:

Untitled

joinini / git-demo 名字

forked from etaon/git-demo 来源

joinini在线编辑:

Untitled

提交:

Untitled

创建一个pull request

Untitled

提交以后:

在joinini账户中,发现转到etaon/git-demo

Untitled

etaon操作

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

Untitled

进入request还可以发起聊天

Untitled

Untitled

joinini可以看到:

Untitled

合并代码:

Untitled

得到结果

Untitled

本地库更新

当然,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
  • 文章目录
  • 站点概览
Etaon

Etaon

Kepp Going!

80 日志
15 分类
43 标签
GitHub CSDN
友情链接
  • Kubernetes
  • Cisco
  • W3School
  • 廖雪峰
标签云
  • Mysql
  • Aws
  • Dql
  • Hadoop
  • Kubernetes
  • Nsx t
  • Redis
  • Azure
  • Cicd
  • Git
  • 团队内协作
    • 准备工作
    • 远程仓库操作
    • 邀请合作者
    • 合作者加入
  • 跨团队协作
    • fork仓库
    • joinini在线编辑:
    • etaon操作
    • 本地库更新
© 2010 - 2023 路无止境!
Powered by - Hugo v0.101.0 / Theme by - NexT
/
Storage by Azure static web apps /
0%