git同步推送代码至gitee和阿里云效

背景

已有阿里云效的代码库,想迁移gitee却迁移不了,只能把代码先拉取下来,然后重新建库,配置过后,采用同步推送的方式,同步两个库的代码。

步骤一 新建名称相同的库 

在gitee上新建库

git同步推送代码至gitee和阿里云效_第1张图片

 

在阿里云效上新建库

 git同步推送代码至gitee和阿里云效_第2张图片

步骤二 配置本地仓库

1. 初始化本地仓库 

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent
$ git init
Initialized empty Git repository in E:/mango-upc/upc-single/mango-upc-parent/.gi
t/

2. 修改.git文件夹的config文件

git同步推送代码至gitee和阿里云效_第3张图片

git同步推送代码至gitee和阿里云效_第4张图片 

filemode = false ==> filemode = true

 3. 添加两个远程仓库

git同步推送代码至gitee和阿里云效_第5张图片

 

 

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ git remote add gitee [email protected]:chenxin04187/mango-upc-parent.git

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ git remote add codeup [email protected]:62805d210065edd3d51a8664/mango-upc/upc-single/mango-upc-parent.git

4. 查看已添加的远程仓库

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ git remote -v
codeup  [email protected]:62805d210065edd3d51a8664/mango-upc/upc-single/mang
o-upc-parent.git (fetch)
codeup  [email protected]:62805d210065edd3d51a8664/mango-upc/upc-single/mang
o-upc-parent.git (push)
gitee   [email protected]:chenxin04187/mango-upc-parent.git (fetch)
gitee   [email protected]:chenxin04187/mango-upc-parent.git (push)

这样就说明已经添加成功了。

步骤三 配置公钥

1. 输入如下命令设置公钥,邮箱地址是gitee和阿里云效绑定的邮箱(两者是相同的)

git同步推送代码至gitee和阿里云效_第6张图片

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ ssh-keygen -t ed25519 -C "[email protected]"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_ed25519
Your public key has been saved in /c/Users/Administrator/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:6N5mUtL0SIJYhcUEbbfTNP1JmYVgKZb/7q0ANkloSYw [email protected]
The key's randomart image is:
+--[ED25519 256]--+
|    .O+o.  ooo =.|
|    o E.oo*.o =  |
|   o o .+=.+ o . |
|  . . .o=.... o  |
|      .=S+=  .   |
|     .. +..o  .  |
|      .o    ..   |
|     ...o    ... |
|      .+.    .o..|
+----[SHA256]-----+

2. 在 C:\Users\Administrator\.ssh目录下找到.pub结尾的文件,打开后复制里面的内容,配置为gitee和阿里云效的公钥

2.1 配置gitee的个人公钥(一定要是个人公钥)

git同步推送代码至gitee和阿里云效_第7张图片

git同步推送代码至gitee和阿里云效_第8张图片2.2  配置阿里云效的公钥

git同步推送代码至gitee和阿里云效_第9张图片

3. 验证密钥 (一定要验证)

git同步推送代码至gitee和阿里云效_第10张图片

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ ssh -T [email protected]
The authenticity of host 'gitee.com (180.76.198.77)' can't be established.
ED25519 key fingerprint is SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts.
Hi xxxx(@xxxx)! You've successfully authenticated, but GITEE.COM does not provide shell access.

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ ssh -T [email protected]
The authenticity of host 'codeup.aliyun.com (118.31.165.50)' can't be established.
RSA key fingerprint is SHA256:yEGmgQNVrc3QAvDvoBrTCF2s07KwmmQ+AbWi9vSt/fE.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'codeup.aliyun.com' (RSA) to the list of known hosts.
Welcome to Codeup, [email protected]!

 验证完成后在C:\Users\Administrator\.ssh目录下会多一个known_hosts的文件,里面存放着已知的host

步骤四 推送代码

本次操作为同步推送已有仓库,所以是这样弄的:

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ git add ./

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ git commit -m "迁移工程"
[master (root-commit) a9340c9] 迁移工程
 3 files changed, 262 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 README.md
 create mode 100644 pom.xml

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ git push --all gitee
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 16 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 2.79 KiB | 2.79 MiB/s, done.
Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:chenxin04187/mango-upc-parent.git
 * [new branch]      master -> master

Administrator@USER-20220820DL MINGW64 /e/mango-upc/upc-single/mango-upc-parent (master)
$ git push --all codeup
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 16 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 2.79 KiB | 2.79 MiB/s, done.
Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
To codeup.aliyun.com:62805d210065edd3d51a8664/mango-upc/upc-single/mango-upc-par
ent.git
 * [new branch]      master -> master

如下命令默认推送到当前分支,所以可以在开发完后,直接用这个命令推送即可

$ git push --all codeup
$ git push --all gitee

推送tag

$ git push --tags codeup
$ git push --tags gitee

 

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