Git远程仓库同步代码全攻略:从基础操作到避坑指南

🔥个人主页:Cx330🌸
❄️个人专栏:《C语言》《LeetCode刷题集》《数据结构-初阶》《C++知识分享》
《优选算法指南-必刷经典100题》《Linux操作系统》:从入门到入魔
🌟心向往之行必能至
🎥Cx330🌸的简介:

目录
前言:
本文聚焦 Git 远程同步的核心需求,摒弃复杂冗余的理论,以 “场景化 + 实操性” 为核心,从基础配置到进阶技巧,再到高频坑点规避,系统拆解克隆、拉取、推送三大核心场景。无论你是新加入项目的开发者、需要跨设备同步代码的独立开发者,还是面临多人协作冲突的团队成员,都能通过本文快速掌握安全同步的步骤、冲突处理的关键方法,以及实用的避坑策略。
全文用清晰的步骤、可直接复制的命令、直观的问题解答,帮你跳过 “踩坑” 阶段,建立规范的同步习惯,让 Git 远程协作从 “痛点” 变成 “顺途”。
一、了解远程仓库
1.1 理解分布式版本控制系统
我们目前所说的所有内容(工作区,暂存区,版本库等等),都是在本地!也就是在你的笔记本或者计算机上。而我们的 Git其实是分布式版本控制系统! 什么意思呢?
可以简单理解为,我们每个人的电脑上都是一个完整的版本库,这样你工作的时候,就不需要联网了,因为版本库就在你自己的电脑上,既然每个人电脑上都有一个完整的版本库,那多个人如何协作呢?比方说你在自己电脑上改了文件A,你的同事也在他的电脑上改了文件A,这时,你们俩之间只需把各自的修改推送给对方,就可以互相看到对方的修改了。

分布式版本控制系统的安全性要高很多,因为每个人电脑里都有完整的版本库,某一个人的电脑坏掉了不要紧,随便从其他人那里复制一个就可以了。
在实际使用分布式管理系统的时候,其实很少在两人之间的电脑上推送版本库的修改,因为可能你们俩不在一个局域网内,两台电脑互相访问不了。也可能今天你的同事病了,他的电脑压根就没打开。因此,分布式控制系统通常也有一台充当“中央服务器”的电脑,但这个服务器的作用仅仅是用来方便“交换”大家的修改,没有它大家也一样干活,只是交换修改不方便而已。有了这个“中央服务器”的电脑,这样就不拍本地出现什么故障看(比如运气差,硬盘坏了,上面的所有东西全部丢失,包括git的所有内容)
1.2 了解什么是远程仓库?
远程仓库是托管在服务器上的 Git 仓库(如 Gitee、GitHub),与本地仓库的关系可概括为:
本地仓库:仅存于个人设备,适合单人开发时的版本控制;远程仓库:存于云端,支持多人访问,核心作用是 “代码共享” 与 “数据备份”。
github 是国外的网站,速度比较慢,我们同统⼀采用码云来托管代码。下来,我们从零开始,使用⼀下码云远程仓
二、远程仓库核心操作
2.1 创建远程仓库
1. 新建远程项目仓库:

2. 填写基本信息:

3. 查看创建的仓库:

4. 创建成功后,我们可以将仓库设置为开源,点击管理选项:


5. 从创建好的远程仓库中我们便能看到,之前在本地学习过的分支,也存在于远程仓库中并被管理起来了,刚创建的仓库有且仅有一个默认的master分支

2.2 克隆远程仓库
克隆/下载远端仓库到本地,需要使用 git clone 命令,后面跟上我们的远端仓库的链接,远端仓库的链接可以在仓库中找到:选择 “克隆/下载” 获取远程仓库链接,克隆后会自动关联远程仓库(master分支):

SSH协议和HTTPS协议是Git最常用使用的两种数据传输协议。SSH协议使用了公钥加密和公钥登录机制,体现了其实用性和安全性,使用此协议需要将我们的公钥放上服务器,由Git服务器进行管理。使用HTTPS方式时,没有要求,可以直接克隆下来。
HTTPS方式:
yhr@VM-24-15-ubuntu:~$ git clone https://gitee.com/ynua-haoran/gitcode.git Cloning into 'gitcode'... remote: Enumerating objects: 7, done. remote: Counting objects: 100% (7/7), done. remote: Compressing objects: 100% (7/7), done. remote: Total 7 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) Receiving objects: 100% (7/7), 2.19 KiB | 172.00 KiB/s, done. yhr@VM-24-15-ubuntu:~$ ls gitcode yhr@VM-24-15-ubuntu:~$ cd gitcode yhr@VM-24-15-ubuntu:~/gitcode$ ls README.en.md README.md yhr@VM-24-15-ubuntu:~/gitcode$ ls -al total 24 drwxrwxr-x 4 yhr yhr 4096 Dec 14 13:44 . drwxr-x--- 4 yhr yhr 4096 Dec 14 13:44 .. drwxrwxr-x 8 yhr yhr 4096 Dec 14 13:44 .git drwxrwxr-x 2 yhr yhr 4096 Dec 14 13:44 .gitee -rw-rw-r-- 1 yhr yhr 820 Dec 14 13:44 README.en.md -rw-rw-r-- 1 yhr yhr 909 Dec 14 13:44 README.md SSH方式:

yhr@VM-24-15-ubuntu:~$ git clone [email protected]:ynua-haoran/gitcode.git Cloning into 'gitcode'... The authenticity of host 'gitee.com (180.76.199.13)' 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])? ^C 使用 SSH 方式克隆仓库,由于我们没有添加公钥到远端库中,服务器拒绝了我们的 clone 链接。需要我们区设置一下:
第一步:创建 SSH Key。在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有 id_rsa 和 id_rsa.pub 这两个文件,如果已经有了,可直接跳到下一步。如果没有,需要创建SSH Key:
yhr@VM-24-15-ubuntu:~$ mkdir .ssh yhr@VM-24-15-ubuntu:~$ ls -al total 64 drwxr-x--- 4 yhr yhr 4096 Dec 15 10:40 . drwxr-xr-x 5 root root 4096 Nov 1 19:36 .. -rw------- 1 yhr yhr 11865 Dec 15 10:40 .bash_history -rw-r--r-- 1 yhr yhr 220 Nov 1 19:36 .bash_logout -rw-r--r-- 1 yhr yhr 3771 Nov 1 19:36 .bashrc drwx------ 3 yhr yhr 4096 Dec 9 16:33 .config -rw-rw-r-- 1 yhr yhr 45 Dec 3 09:25 .gitconfig -rw------- 1 yhr yhr 20 Dec 12 10:58 .lesshst -rw-r--r-- 1 yhr yhr 807 Nov 1 19:36 .profile drwxrwxr-x 2 yhr yhr 4096 Dec 15 10:40 .ssh -rw------- 1 yhr yhr 8637 Dec 12 10:21 .viminfo -rw-rw-r-- 1 yhr yhr 7 Nov 14 20:06 .vimrc yhr@VM-24-15-ubuntu:~$ ssh-keygen -t rsa -C "[email protected]" Generating public/private rsa key pair. Enter file in which to save the key (/home/yhr/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/yhr/.ssh/id_rsa Your public key has been saved in /home/yhr/.ssh/id_rsa.pub The key fingerprint is: SHA256:zrGmeeR59lfgXKs+nGt2bMldqaI/rpLDYW3iqEKn2kE [email protected] The key's randomart image is: +---[RSA 3072]----+ | | | | | | | . .| | E S o oo| | o . *.= ooo| |. + =oX. . *.+| | + . . X+ oo O.*.| |o o.. o.o==+B+= | +----[SHA256]-----+ yhr@VM-24-15-ubuntu:~$ cd .ssh/ yhr@VM-24-15-ubuntu:~/.ssh$ ls id_rsa id_rsa.pub 注意:我这里没有.ssh文件,所以我mkdir .ssh创建了一个,如果大家ls发现有.ssh文件就可以不用创建!
顺利的话,我们可以在用户主目录里找到 .ssh 目录,里面有 id_rsa 和 id_rsa.pub 两个文件,这两个就算SSH Key的秘钥对,id_rsa是私钥,不能泄漏出去, id_rsa.pub 是公钥,可以放心地告诉任何人
第二步:添加自己的公钥到远端仓库。
yhr@VM-24-15-ubuntu:~/.ssh$ cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDLTO8ltKCAmG+MGWm5/ZvRilafYPvcD7jWi19ifGzuYeuBvfC9JsKUJbDRzQRHkAw/0jzLjStANT8dmL6WZ3+HcN6XFQKU3+w5QVly8li6KC94C7q2OnHvCxcsWoIZL2N3S9mLa4Svw89T0STPt+F3dnrNZU+XoCHxV935Ro+GSXohG8Ahtg0SiTeE1YOesEWqe/JU8tKKdYsvPo6RQo0BsnchPJcZtHpDB+p8v28m9NJosIwkEhgGCzdmzcoHy5ZETXHE/X2EKWpi/56DeHSAnFpEMEYhClESI3aQRSMD2bjEVUH6rUeWlLC6micn+gtMtrI5tS2nkQOQFv4XWDQ9eQ7KzCR3OlCPqAABhgEPsmX6rxUz+mzLISTVw6K/V/mXWB/1O0HomlRO4AKFNfKHZKXn1ozFzpKBO1/hHfKAP5VDyAgiMrMZSNVSYYCISR6rs3gViv+u2rytHpe0OksQmSTgHMMSNhfD21DPP/FoM5LBWyEfK/ypJ2cCRJPswTU= [email protected] 
点击确定后,输入gitee密码即可成功添加公钥

yhr@VM-24-15-ubuntu:~$ git clone [email protected]:ynua-haoran/gitcode.git Cloning into 'gitcode'... The authenticity of host 'gitee.com (180.76.199.13)' 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. Receiving objects: 100% (7/7), done. remote: Total 7 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) done,成功!如果有多个人协作开发,GitHub/Gitee 允许添加多个公钥,只要把每个人电脑上的Key都添加到 GitHub/Gitee,就可以在每台电脑上往 GitHub/Gitee 上提交推送了。
当我们从远程仓库克隆后,实际上Git会自动把本地的master分支和远程的master分支对应起来,并且远程仓库的默认名称是 origin。在本地我们可以使用 git remote 命令,查看远程库的信息,如:
yhr@VM-24-15-ubuntu:~$ cd gitcode yhr@VM-24-15-ubuntu:~/gitcode$ ls README.en.md README.md yhr@VM-24-15-ubuntu:~/gitcode$ git remote origin 或者,用 git remote -v 显示更详细的信息
三. 向远程仓库推送和拉取本地仓库的操作
3.1 向远程仓库推送
本地已经 clone 成功远程仓库后,我们便可以向仓库中提交内容。例如新增一个file.txt文件:
yhr@VM-24-15-ubuntu:~/gitcode$ git branch * master yhr@VM-24-15-ubuntu:~/gitcode$ vim file.txt yhr@VM-24-15-ubuntu:~/gitcode$ git add . yhr@VM-24-15-ubuntu:~/gitcode$ git commit -m "create file.txt" [master f066be5] create file.txt 1 file changed, 1 insertion(+) create mode 100644 file.txt yhr@VM-24-15-ubuntu:~/gitcode$ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean 提交时需要注意,如果我们之前设置过全局的name和email,这两项配置需要和gitee上配置的用户名和邮箱一致,否则会出错。或者从来没有设置过全局的name和email,那么我们第一次提交时也会报错。这就需要我们重新配置下了,同样要注意需要和gitee上配置的用户名以及邮箱一致,如何配置之前讲过了,在这里就不再赘述。
到这里我们已经将内容提交至本地仓库中,如何将本地仓库的内容推送至远程仓库呢,需要使用 git push 命令。该命令用于将本地的分支版本上传到远程并合并,命令格式如下:
git push <远程主机名> <本地分⽀名>:<远程分⽀名> # 如果本地分⽀名与远程分⽀名相同,则可以省略冒号: git push <远程主机名> <本地分⽀名>此时我们要将本地的 master 分支推送到 origin 主机的 master 分支,则可以:
yhr@VM-24-15-ubuntu:~/gitcode$ git push origin master:master Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 2 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 270 bytes | 270.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [1.1.23] remote: Set trace flag 2d465eaf To gitee.com:ynua-haoran/gitcode.git 42691b0..f066be5 master -> master 推送成功!这里由于我们使用的是 SSH 协议,是不用每一次推送都输入密码的,方便了我们推送操作。如果你使用的是HTTPS协议,有个麻烦的地方就是每次推送都必须输入口令。
接下来,看看码云远端:

代码已经被推送到远端了:

3.2 拉取远程仓库
从远程获取最新代码并合并到本地,避免本地代码落后导致冲突,常用命令有git fetch(仅获取不合并)和git pull(获取并合并):我们这里主要讲讲 git pull,下面的修改操作仅作为演示,实际使用中大家不要在码云上直接去修改内容
点击编辑:增加一行代码,点击保存就可以了

此时,远程仓库是要领先于本地仓库一个版本,为了使本地仓库保持最新的版本,我们需要拉去下远端代码,并合并到本地。Git 提供了 git pull 命令,用于从远程获取代码并合并到本地的版本,格式如下:
git pull <远程主机名> <远程分⽀名>:<本地分⽀名> # 如果远程分⽀是与当前分⽀合并,则冒号后⾯的部分可以省略。 git pull <远程主机名> <远程分⽀名> yhr@VM-24-15-ubuntu:~/gitcode$ git pull origin master:master remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0) Unpacking objects: 100% (3/3), 965 bytes | 965.00 KiB/s, done. From gitee.com:ynua-haoran/gitcode f066be5..f779230 master -> master f066be5..f779230 master -> origin/master warning: fetch updated the current branch head. fast-forwarding your working tree from commit f066be5ed7f4dc036752e5e1563d9a1f50fe078a. Already up to date. yhr@VM-24-15-ubuntu:~/gitcode$ cat file.txt hello git hello world yhr@VM-24-15-ubuntu:~/gitcode$ git status On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean 到这里检查,没有文件可以commit了,就说明我们拉取成功了!
四. 忽略特殊文件以及给命令配置别名
4.1 忽略特殊文件:.gitignore 配置
在日常开发中,我们有些文件不想或者不应该提交到远端,比如保存了数据库密码的配置文件,那怎么能让 Git 知道呢?所以我们在 Git 工作区的根目录下创建一个特殊的 .gitignore 文件,然后把要忽略的文件名填进去,Git就会自动忽略这些文件了。
不过我们其实也不需要从头写 .gitignore 文件,gitee 在创建仓库时就可以为我们生成,不过需要我们主动勾选一下(有很多种,大家可以按需选择):

那要是我们创建的时候没有选择这个,在工作区创建一个也是可以的,无论时哪一种方式,最终都可以得到一个完整的 .gitignore 文件,例如我们想忽略以 .so 和 .ini 结尾的所有文件, .gitignore 的内容如下:
# 可以直接写文件 *.ini *.so 在 .gitignore 文件中也可以指定某个确定的文件。
最后一步就是把 .gitignore 也提交到远端,就完成了:
yhr@VM-24-15-ubuntu:~/gitcode$ git status On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore nothing added to commit but untracked files present (use "git add" to track) 接下来,我们测试一下 .gitignore 文件的魅力,我们新建 b.so和 c.so文件:
yhr@VM-24-15-ubuntu:~/gitcode$ touch b.so yhr@VM-24-15-ubuntu:~/gitcode$ git add -f b.so yhr@VM-24-15-ubuntu:~/gitcode$ git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: .gitignore new file: b.so yhr@VM-24-15-ubuntu:~/gitcode$ vim .gitignore yhr@VM-24-15-ubuntu:~/gitcode$ touch c.so yhr@VM-24-15-ubuntu:~/gitcode$ git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: .gitignore new file: b.so Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: .gitignore Untracked files: (use "git add <file>..." to include in what will be committed) c.so yhr@VM-24-15-ubuntu:~/gitcode$ cat .gitignore #可以直接写文件名 *.so *.ini !c.so 检验 .gitignore 的标准就是 git status 命令是不是说 working tree clean。我们发现 Git 并没有提示在工作区有文件新增,那我们的 .gitignore 就生效了。
但有些时候,你就是想添加一个文件到 Git,但由于这个文件被 .gitignore 忽略了,根本添加不了,那么可以用 -f 强制添加:
yhr@VM-24-15-ubuntu:~/gitcode$ git add -f b.so 或者你发现,可能是 .gitignore 写得有问题,需要找出来到底哪个规则写错了,比如说 a.so 文件是要被添加的,可以用 git check-ignore 命令来检查:
yhr@VM-24-15-ubuntu:~/gitcode$ git check-ignore -v d.so .gitignore:3:*.so d.so 这里我们就可以看到,第三行需要忽略 .so 文件,所以忽略 d.so 文件的原因就在 .gitignore 文件的第三行,如果我们想要不排除哪个文件,可以在前面加上 ! 操作如下:
#可以直接写文件名 *.so *.ini !c.so 4.2 给命令配置别名
在我们使用 Git 期间,有些命令敲的时候太长了很麻烦,我们的git支持对命令进行简化!比如将 git status 简化为 git st,对应的命令为:
yhr@VM-24-15-ubuntu:~/gitcode$ git config --global alias.st status yhr@VM-24-15-ubuntu:~/gitcode$ git st On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean yhr@VM-24-15-ubuntu:~/gitcode$ git status On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean 我们再来配置一个git lpa让其达到 git log --pretty=oneline --abbrev-commit 的效果
yhr@VM-24-15-ubuntu:~/gitcode$ git config --global alias.lpa 'log --pretty=oneline --abbrev-commit' yhr@VM-24-15-ubuntu:~/gitcode$ git lpa 602b6fc (HEAD -> master, origin/master, origin/HEAD) md f779230 update file.txt. f066be5 create file.txt 42691b0 Initial commit 不过还是不建议大家刚开始学习就这样做,我们需要尽快适应Git
五. 标签管理
标签(tag)是对某次提交 (commit) 的别名(如v1.0),比复杂的 commit id 更易记忆,适合标记发布版本:
5.1 创建标签
命令 git tag [name] 就可以打一个新的标签,并用 git tag 查看所有标签:
yhr@VM-24-15-ubuntu:~/gitcode$ git tag v1.0 yhr@VM-24-15-ubuntu:~/gitcode$ git tag v1.0 默认标签是打在最新提交的 commit 上的。那如何在指定的 commit 上打标签呢?方法是找到历史提交的 commit id,然后打上就可以了,示例如下:
yhr@VM-24-15-ubuntu:~/gitcode$ git log --pretty=oneline --abbrev-commit 602b6fc (HEAD -> master, tag: v1.0, origin/master, origin/HEAD) md f779230 update file.txt. f066be5 create file.txt 42691b0 Initial commit yhr@VM-24-15-ubuntu:~/gitcode$ git tag v0.9 f779230 yhr@VM-24-15-ubuntu:~/gitcode$ git tag v0.9 v1.0 Git 还提供可以创建带有说明的标签,用 -a 指定标签名,-m 指定说明文字,格式为:
yhr@VM-24-15-ubuntu:~/gitcode$ git tag -a v0.8 -m "important tag:XXX" f066be5 yhr@VM-24-15-ubuntu:~/gitcode$ git tag v0.8 v0.9 v1.0 注意,标签不是按时间顺序列出,而是按字母排序的。
可以用 git show [tagname] 查看标签信息。
yhr@VM-24-15-ubuntu:~/gitcode$ git show v0.8 tag v0.8 Tagger: yhr <[email protected]> Date: Mon Dec 15 13:45:47 2025 +0800 important tag:XXX commit f066be5ed7f4dc036752e5e1563d9a1f50fe078a (tag: v0.8) Author: yhr <[email protected]> Date: Mon Dec 15 12:15:26 2025 +0800 create file.txt diff --git a/file.txt b/file.txt new file mode 100644 index 0000000..8d0e412 --- /dev/null +++ b/file.txt @@ -0,0 +1 @@ +hello git 5.2 操作标签
如果标签打错了,也可以删除:
yhr@VM-24-15-ubuntu:~/gitcode$ git tag -d v0.9 Deleted tag 'v0.9' (was f779230) yhr@VM-24-15-ubuntu:~/gitcode$ git tag v0.8 v1.0 因为创建的标签都只是存储在本地,不会自动推送到远程。所以,打错的标签可以在本地安全删除。
如果要推送某个标签到远程,使用命令 git push origin <tagname>
yhr@VM-24-15-ubuntu:~/gitcode$ git tag v0.8 v1.0 yhr@VM-24-15-ubuntu:~/gitcode$ git push origin v1.0 Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [1.1.23] remote: Set trace flag 524e8ea8 To gitee.com:ynua-haoran/gitcode.git * [new tag] v1.0 -> v1.0 当然,如果你本地有很多标签,也可以一次全部推送到远端:
yhr@VM-24-15-ubuntu:~/gitcode$ git push origin --tags Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 159 bytes | 159.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [1.1.23] remote: Set trace flag ae458986 To gitee.com:ynua-haoran/gitcode.git * [new tag] v0.8 -> v0.8 我们查看 gitee 发现标签已经更新了:

如果标签已经推送到远端仓库了,此时删除就得先在本地仓库删除,然后再推送到远端:
yhr@VM-24-15-ubuntu:~/gitcode$ git tag -d v0.9 Deleted tag 'v0.9' (was f779230) yhr@VM-24-15-ubuntu:~/gitcode$ git tag v0.8 v1.0 yhr@VM-24-15-ubuntu:~/gitcode$ git push origin v1.0 Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [1.1.23] remote: Set trace flag 524e8ea8 To gitee.com:ynua-haoran/gitcode.git * [new tag] v1.0 -> v1.0 yhr@VM-24-15-ubuntu:~/gitcode$ git push origin --tags Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 159 bytes | 159.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [1.1.23] remote: Set trace flag ae458986 To gitee.com:ynua-haoran/gitcode.git * [new tag] v0.8 -> v0.8 yhr@VM-24-15-ubuntu:~/gitcode$ git tag -d v1.0 Deleted tag 'v1.0' (was 602b6fc) yhr@VM-24-15-ubuntu:~/gitcode$ git push origin :v1.0 remote: Powered by GITEE.COM [1.1.23] remote: Set trace flag 4948d598 To gitee.com:ynua-haoran/gitcode.git - [deleted] v1.0 我们再来看一下远端:

可以发现远端也删除成功啦!
总结:
结语:Git 远程同步的核心逻辑从未复杂 —— 本质是 “保持本地与远程的一致性”,但真正落地时,冲突处理、权限配置、操作顺序等细节往往成为效率瓶颈。本文梳理的场景化操作与避坑指南,正是为了帮你规避这些细节陷阱,让同步流程更顺畅