[Git/SVN] Gitee使用教程
阅读原文时间:2023年07月22日阅读:25

1 Gitee

Gitee 提供免费的 Git 仓库,还集成了代码质量检测、项目演示等功能。

对于团队协作开发,Gitee 还提供了项目管理代码托管文档管理的服务,5 人以下小团队免费。

Step1 前期准备

  • Step1.1 本地电脑安装Git

https://git-scm.com/

  • Step1.2 申请Gitee账号

https://gitee.com/

  • Step1.3 在Gitee新建仓库(私有 or 公有)


> 本图摘自网友: 魏一鹤

创建完成后:

Step2 安装插件:打开IDEA-Settings-Plugins-Gitee

Step3 IDEA-Settings-Version Control-Gitee,输入账号、密码

Step4 IDEA-VCS-Import into Version Control-Share Project on Gitee

Step4 在Gitee下载离线源码Zip包,并解压

可对解压后的文件目录进行重命名。例如:去除-master

Step5 IDEA-Open-(选中本地目标Git仓库目录)-OK

Step6 IDEA窗口中添加子模块、添加新文件

例如:在根目录下添加子工程、pom.xml、右键选中As a Maven Project、…

Step6 启用GIT版本控制集成

  • 方法1:IDEA-VCS-Enable Version Control Intergration-Git


  • 方法2:IDEA-Settings-Version Control-+-(填写源码地址、VCS=GIT)

Step7 查验本地git仓库状态

git status

git config --list

Step8 在Gitee配置公钥

  • 本地电脑生成私钥 id_rsa.pub

    C:\Users{USER_NAME}.ssh

  • 登录Gitee(个人头像)-设置-SSH公钥-(填写{标题}{公钥})

Step9 为本地GIT仓库设置远程仓库地址

此时仍然无法pull代码

  • 原因:未挂载远程仓库的分支
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> master

  • Step9.1 为本地GIT仓库设置远程仓库地址

方式1 使用此种方式可以在本地分支已经追踪了某个远程分支的情况下,修改追踪的远程分支

git branch --set-upstream-to={远程主机名}/{远程分支名} {本地分支名}

方式2 加上-u参数,这样push时,本地指定分支就和远程主机的同名分支建立追踪关系

git push -u <远程主机名> <本地分支名>

方式3 新分支指针指向 <远程主机名>/<远程分支名> 所指的位置

git checkout -b <本地分支名> <远程主机名>/<远程分支名>
  • 重要技巧

    git pull
    git pull origin master
    git pull origin master --allow-unrelated-histories


    git push -u origin master -f

之后就可以随意push、pull了

X 参考文献

配置本地同一仓库,可自由推送至不同的云端远程仓库

https://speedssx.com/user/payment