当前位置: 首页 > news >正文

【git】-- 远程操作

文章目录

  • 4. 远程操作
    • 4.1 克隆远程仓库
      • 4.1.1 HTTPS
      • 4.1.2 SSH
    • 4.2 查看远程仓库
    • 4.3 推送到远程仓库
    • 4.4 拉取远程仓库
      • 4.4.1 方式1
      • 4.4.2 方式2
    • 4.5 忽略特殊文件
    • 4.6 配置命令的别名

更多Git相关知识: Git专栏

4. 远程操作

Git是一个分布式版本控制系统

4.1 克隆远程仓库

4.1.1 HTTPS

root@VM-0-3-ubuntu:~# git clone https://gitee.com/pepper-cloth/remote-gitcode.gitCloning into'remote-gitcode'... remote: Enumerating objects:7, done. remote: Counting objects:100%(7/7), done. remote: Compressing objects:100%(7/7), done. remote: Total7(delta0), reused0(delta0), pack-reused0(from0)Receiving objects:100%(7/7), done.

4.1.2 SSH

  1. 第一步:创建SSHKey。
    在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa 和 id_rsa.pub 这两个文件,如果已经有了,可直接跳到下一步。
    如果没有,需要创建SSH Key:
    邮箱需要和码云上的邮箱保持一致
root@VM-0-3-ubuntu:~/.ssh# ssh-keygen -t rsa -C "1186710125@qq.com"Generating public/private rsa key pair. Enterfileinwhichto save the key(/root/.ssh/id_rsa): Enter passphrase(emptyforno passphrase): Enter same passphrase again: Your identification has been savedin/root/.ssh/id_rsa Your public key has been savedin/root/.ssh/id_rsa.pub The key fingerprint is: SHA256:RkjtuKVEOXYXwhGfQLHyTo9rGmElz39ImVTwe81bTvQ1186710125@qq.com The key's randomart image is: +---[RSA3072]----+|.=B+oo.||.=.+=.+||o+=+.+..||oOo. o.+.||.o+S +..E||.o==..oo||.o +...||....||.o.|+----[SHA256]-----+ root@VM-0-3-ubuntu:~/.ssh# laauthorized_keys id_rsa id_rsa.pub
  1. 添加公钥到远程仓库

获取公钥:

root@VM-0-3-ubuntu:~/.ssh# laauthorized_keys id_rsa id_rsa.pub root@VM-0-3-ubuntu:~/.ssh# cat id_rsa.pubssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCnKTqyd7B1aNm/IfEj2/CML6C05AkqBTKUOdN7iJEt04+XryeDcrtC8voIZRkeWV1eD/AYToOjZlTr/nuKMq6AD+LXic9ykOXILPF4GhR9jBI2vUg0f08UdrP41p1bsz6YmKkumUbD/Ezx8ch0JqHzm2oQkHqinYq7lM8KTGiO0iDPiGbdled9m03/iH86uMqjvpQplwKE6z88VxeWeNUKdfhKMusGDsAcd36+grDpXeAab4pOZQcXJyLtenLf/r44Bm8AOTkAlDu0SXxASKVxx3LfRpkQlCMhy4z6uBUNspi/W6XXs5ntJmMyxzOFk4wawBzFQQNzENJeoJlzp12fATGDsR0EJ9OXoWalUGPh5g8OJCq3ZsAMyfYKmZpXdhLxUHizgbeTK4LEEQcKjvxHkKFRl31HjMAYv5qQkqgQDthvM1p4YZTu/BrL6N2AYW/8GdVPyxIChpi3pxS+NETJpxNk+M/xOjlBfVPPPjNjBUu+yGWYA7IZbaifFFUY2FE=1186710125@qq.com

添加:

  1. 克隆
root@VM-0-3-ubuntu:~# git clone git@gitee.com:pepper-cloth/remote-gitcode.gitCloning into'remote-gitcode'... The authenticity ofhost'gitee.com (180.76.198.225)'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. remote: Enumerating objects:7, done. remote: Counting objects:100%(7/7), done. remote: Compressing objects:100%(7/7), done. remote: Total7(delta0), reused0(delta0), pack-reused0(from0)Receiving objects:100%(7/7), done. root@VM-0-3-ubuntu:~# lsget-docker.sh gitcode remote-gitcode
  1. 检查用户名和邮箱
    本地仓库配置中的用户名和邮箱需要和码云平台上的配置一模一样。
root@VM-0-3-ubuntu:~/remote-gitcode# git config -luser.name=cuckoouser.email=buxinyu163@163.comcore.repositoryformatversion=0core.filemode=truecore.bare=falsecore.logallrefupdates=trueremote.origin.url=git@gitee.com:pepper-cloth/remote-gitcode.gitremote.origin.fetch=+refs/heads/*:refs/remotes/origin/*branch.master.remote=originbranch.master.merge=refs/heads/master root@VM-0-3-ubuntu:~/remote-gitcode# git config --global user.name "pepper-cloth"root@VM-0-3-ubuntu:~/remote-gitcode# git config --global user.email "1186710125@qq.com"root@VM-0-3-ubuntu:~/remote-gitcode# git config -luser.name=pepper-clothuser.email=1186710125@qq.comcore.repositoryformatversion=0core.filemode=truecore.bare=falsecore.logallrefupdates=trueremote.origin.url=git@gitee.com:pepper-cloth/remote-gitcode.gitremote.origin.fetch=+refs/heads/*:refs/remotes/origin/*branch.master.remote=originbranch.master.merge=refs/heads/master

4.2 查看远程仓库

root@VM-0-3-ubuntu:~/remote-gitcode# git remoteorigin

origin:是远程仓库的默认名。

查看远程仓库更详细的信息:

root@VM-0-3-ubuntu:~/remote-gitcode# git remote -vorigin https://gitee.com/pepper-cloth/remote-gitcode.git(fetch)origin https://gitee.com/pepper-cloth/remote-gitcode.git(push)

4.3 推送到远程仓库

将本地仓库中的某一个分支下的内容,推送到远程仓库中的对应分支下。

gitpush origin 本地分支名:远程分支名

如果本地分支名和远程分支名一致的话,可以省略git push origin 分支名

root@VM-0-3-ubuntu:~/remote-gitcode# touch file.txtroot@VM-0-3-ubuntu:~/remote-gitcode# vim file.txtroot@VM-0-3-ubuntu:~/remote-gitcode# cat file.txthellogitroot@VM-0-3-ubuntu:~/remote-gitcode# git add .root@VM-0-3-ubuntu:~/remote-gitcode# git commit -m "add file.txt"[master f4179bf]addfile.txt1filechanged,1insertion(+)create mode100644file.txt root@VM-0-3-ubuntu:~/remote-gitcode# git push origin master:masterTotal0(delta0), reused0(delta0), pack-reused0remote: Powered by GITEE.COM[1.1.23]remote: Set trace flag 0c4f9e90 To gitee.com:pepper-cloth/remote-gitcode.git f59a47a..f4179bf master ->master

4.4 拉取远程仓库

假设现在有其他的小伙伴进行了修改,我们需要拉取远程仓库中的内容。

4.4.1 方式1

拉取命令:git pull origin 远程分支名:本地分支名,同样,如果一样,可以省略。

root@VM-0-3-ubuntu:~/remote-gitcode# cat file.txthellogitroot@VM-0-3-ubuntu:~/remote-gitcode# git pull origin masterremote: Enumerating objects:5, done. remote: Counting objects:100%(5/5), done. remote: Compressing objects:100%(2/2), done. remote: Total3(delta1), reused0(delta0), pack-reused0(from0)Unpacking objects:100%(3/3),947bytes|947.00KiB/s, done. From gitee.com:pepper-cloth/remote-gitcode * branch master ->FETCH_HEAD f4179bf..300659b master ->origin/master Updating f4179bf..300659b Fast-forward file.txt|1+1filechanged,1insertion(+)root@VM-0-3-ubuntu:~/remote-gitcode# cat file.txthellogithello world

4.4.2 方式2

直接使用git pull命令进行拉取,拉取远程仓库的所有内容。

4.5 忽略特殊文件

我们会有并不想将某些文件提交到远程仓库中的需求。只需要在git工作区的根目录下创建一个.gitignore文件,然后把要忽略的文件名填进去,Git就会自动忽略这些文件了。

root@VM-0-3-ubuntu:~/remote-gitcode# vim .gitignoreroot@VM-0-3-ubuntu:~/remote-gitcode# lafile.txt .git .gitee .gitignore README.en.md README.md root@VM-0-3-ubuntu:~/remote-gitcode# cat .gitignore# 可以直接写文件名# 忽略所有以 .so & .ini 结尾的文件*.so *.ini# 不排除b.so文件!b.so

强制提交被忽略的文件:git add -f 文件名

4.6 配置命令的别名

配置:git config --global alias.别名 原来的命令。加了global表示是全局都生效。

比如:将git status简化成git st

root@VM-0-3-ubuntu:~/remote-gitcode# git statusOn branch master Your branch is up todatewith'origin/master'.nothing to commit, working tree clean root@VM-0-3-ubuntu:~/remote-gitcode# git config --global alias.st statusroot@VM-0-3-ubuntu:~/remote-gitcode# git stOn branch master Your branch is up todatewith'origin/master'.nothing to commit, working tree clean

简化完之后,原来完整的命名依旧生效。

http://www.gsyq.cn/news/1464691.html

相关文章:

  • BFS-Best-Face-Swap高级技巧:利用LoRA技术提升换脸效果与效率
  • 从游戏地形到有限元分析:Delaunay三角剖分在Unity和COMSOL中的隐藏用法
  • 提升团队效能,基于快马AI构建chromedriver智能版本管理与自动下载工具
  • KV-Embedding技术:无训练文本嵌入新方法解析
  • arabic_PP-OCRv5_mobile_rec_onnx性能测试报告:准确率、速度和内存占用全面分析
  • 微博话题洞察工作流:Plotly交互式可视化实战
  • 2026年知名的平模门芯板发泡剂/硫氧镁保温发泡剂/水泥发泡剂优质厂家推荐榜 - 行业平台推荐
  • 利用快马AI快速原型化:十分钟构建ccswitch下载管理工具界面
  • 2026年评价高的无机硫氧镁改性剂/硫氧镁门芯改性剂主流厂家对比评测 - 品牌宣传支持者
  • 别再搞混了!手把手教你用D435i跑通VINS-Fusion(单目/双目模式详解)
  • STM32F103裸机移植CanFestival-3保姆级避坑指南(附对象字典生成工具使用)
  • BLE蓝牙老是断连?别慌,这份0x00到0x3E错误码排查指南帮你搞定
  • 如何深度掌控开源笔记工具:Xournal++ 实战进阶指南
  • 机器学习生产化:从模型上线到可信赖系统落地指南
  • Qt数据库开发避坑指南:QSqlTableModel的EditStrategy策略详解与实战选择
  • 手把手教你为团队定制PMD规则:从发现代码坏味道到编写XPath规则文件
  • AI数学推理系统:形式化验证+可控生成的三明治架构
  • 3分钟掌握AI会议截止日期管理:科研工作者的智能时间管理终极指南
  • prima.cpp未来路线图:下一代家庭AI集群的发展方向
  • 用Proteus仿真555+4017流水灯:从原理图到动态效果,手把手调出你想要的频率
  • 2023年软考-新能源采购系统—软件设计师—东方仙盟
  • AI驱动的离职管理革命(从被动响应到主动挽留):基于237家企业的实证分析与落地框架
  • 流程挖掘如何驱动工业4.0组织变革落地
  • HarmonyOS 6 PopoverDialogV2 跟手弹出框使用文档
  • C#上位机开发实战:封装一个可复用的欧姆龙NX PLC通讯库(基于CX-Compolet)
  • Kaggle数据集在Colab中零配置直连加载方案
  • ai赋能硬件开发:让快马平台智能生成dht11自适应环境调节系统代码
  • PG19 要来了!内核级 REPACK + 原生图查询,HOW2026 大咖提前剧透
  • 2026年质量好的养生亚克力浴缸/亚克力浴缸/工程亚克力浴缸/亚克力浴缸代工推荐品牌厂家 - 品牌宣传支持者
  • 从零组装一台NanoVNA:亲手测量你的第一根天线驻波比(附校准全流程)