git 关联 github、gitee 仓库

github 官网创建仓库,取得仓库地址,我的这个是  https://github.com/xue-y/pay.git 

 

gitee 官网点击创建仓库,右上角 新建导入,进入导入页面

 选择语言,点击导入 按钮

  本地克隆远程仓库 

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW
$ git clone git@github.com:xue-y/pay.git
Cloning into 'pay'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), 4.46 KiB | 415.00 KiB/s, done.

 

查看远程仓库地址

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git remote -v
origin  git@github.com:xue-y/pay.git (fetch)
origin  git@github.com:xue-y/pay.git (push)

 

复制 gitee 仓库地址

 添加 gitee 仓库地址

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git remote add gitee_origin git@gitee.com:xue-y/pay.git

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git remote -v
gitee_origin    git@gitee.com:xue-y/pay.git (fetch)
gitee_origin    git@gitee.com:xue-y/pay.git (push)
origin  git@github.com:xue-y/pay.git (fetch)
origin  git@github.com:xue-y/pay.git (push)

 

添加测试文件

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test.txt

nothing added to commit but untracked files present (use "git add" to track)

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git add test.txt

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git commit -m '测试提交文件'
[main 8eb8d41] 测试提交文件
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

 

查看默认仓库,当前 main 分支  追踪 origin 这个远程主机,main 这个远程分支

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git branch -vv
* main 8eb8d41 [origin/main] 测试提交文件

设置追踪关系 ,如:本地名称为 master 要追踪到远程origin/master  git branch --set-upstream-to=origin/master master 

 

push/pull   要分别提交,  git push  提交默认(存在追踪关系的)仓库,提交 gitee 仓库需要指定 远程仓库名称

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 314 bytes | 104.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:xue-y/pay.git
   a3fe3e0..8eb8d41  main -> main

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git push gitee_origin main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 314 bytes | 62.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:xue-y/pay.git
   a3fe3e0..8eb8d41  main -> main

 

push和pull无需额外操作,一次提交,不用分别提交两次仓库

不添加 gitee 远程仓库,而是给 github 添加额外的 URL。使用git remote set-url -add ,给已有的名为name的远程仓库添加一个远程地址,比如:

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git remote set-url --add origin git@gitee.com:xue-y/pay.git
Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git remote -v
gitee_origin    git@gitee.com:xue-y/pay.git (fetch)
gitee_origin    git@gitee.com:xue-y/pay.git (push)
origin  git@github.com:xue-y/pay.git (fetch)
origin  git@github.com:xue-y/pay.git (push)
origin  git@gitee.com:xue-y/pay.git (push)

 

添加测试文件

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test2.txt

nothing added to commit but untracked files present (use "git add" to track)

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git add  test2.txt

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git commit -m '测试提交一次文件'
[main 39050fc] 测试提交一次文件 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test2.txt

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 363 bytes | 45.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:xue-y/pay.git
   f25589c..39050fc  main -> main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 363 bytes | 121.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:xue-y/pay.git
   f25589c..39050fc  main -> main

 

 删除 gitee 仓库

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git remote rm gitee_origin  // 删除远程仓库 gitee_origin 

Think@Think-PC MINGW64 /f/phpStud/PHPTutorial/WWW/pay (main)
$ git remote -v
origin  git@github.com:xue-y/pay.git (fetch)
origin  git@github.com:xue-y/pay.git (push)
origin  git@gitee.com:xue-y/pay.git (push)
posted @ 2023-01-19 14:03  柔和的天空  阅读(144)  评论(0编辑  收藏  举报