当前位置: 首页 > 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.jsqmd.com/news/953074/

相关文章:

  • 2026年6月喷码机企业推荐,大字符喷码机/喷码机/激光喷码机,喷码机实力厂家有哪些 - 品牌推荐师
  • Code to Story:用AST解析构建工程师叙事力
  • BFS-Best-Face-Swap高级技巧:利用LoRA技术提升换脸效果与效率
  • 从游戏地形到有限元分析:Delaunay三角剖分在Unity和COMSOL中的隐藏用法
  • 提升团队效能,基于快马AI构建chromedriver智能版本管理与自动下载工具
  • KV-Embedding技术:无训练文本嵌入新方法解析
  • 2026年知名的不锈钢双层风口/304不锈钢单层风口/不锈钢格栅风口厂家哪家好 - 品牌宣传支持者
  • javascript实战:基于快马平台构建电商商品多条件筛选系统
  • Qt数据库开发避坑指南:QSqlTableModel的三种编辑策略到底怎么选?(OnManualSubmit实例详解)
  • Mutual Information实战指南:非线性特征依赖量化与工程落地
  • 2026年知名的平模门芯板发泡剂/硫氧镁保温发泡剂/水泥发泡剂优质厂家推荐榜 - 行业平台推荐
  • 微博话题洞察工作流:Plotly交互式可视化实战
  • arabic_PP-OCRv5_mobile_rec_onnx性能测试报告:准确率、速度和内存占用全面分析
  • STM32F105双CAN实测工程:CAN1专注接收、CAN2独立发送,开箱即用
  • 压缩感知三大测量矩阵Matlab实现:伯努利、循环、部分傅里叶矩阵一键生成
  • AutoGen本地部署避坑指南:Poetry+Ollama+Chroma全链路实操
  • 2026年评价高的冷饮巧克力酱/耐烘烤巧克力酱/咖啡巧克力酱多家厂家对比分析 - 品牌宣传支持者
  • TongWeb 7.0.C 容器版 vs 企业版:JNDI数据源配置到底差在哪?一个坑位引发的思考
  • 别再踩坑了!手把手教你用Overleaf和本地LaTeX向arXiv提交论文(附.bbl文件处理指南)
  • GPT-4参数量与激活率真相:1.8万亿不是显存需求,2%不是固定计算比例
  • 告别重复劳动:用快马AI辅助一键生成mootdx多股数据清洗与合并代码
  • Linkbricks-Llama3.2-Korean-cpt-3b实战教程:韩语文本生成与对话系统构建
  • 利用快马AI快速原型化:十分钟构建ccswitch下载管理工具界面
  • 2026年评价高的无机硫氧镁改性剂/硫氧镁门芯改性剂主流厂家对比评测 - 品牌宣传支持者
  • STM32F103驱动1.14寸ST7789彩屏的Keil工程源码(含SPI底层+LVGL显示支持)
  • LangGraph实现可审计的人机协同工作流
  • 模板即规则:文档自动化中的低代码视觉协议设计
  • 避坑指南:MicroBlaze软核开发中DDR3和Local Memory配置的那些“坑”与优化策略
  • OpenCV凸包缺陷检测报错‘索引非单调’?自相交轮廓预处理修复方案
  • C#手写数据类和protoc自动生成类的转换