跳到主要内容
极客日志极客日志面向AI+效率的开发者社区
首页博客我的书AI学习GitHub 精选镜像AI 生图工具UI配色美学关于
搜索内容 / 工具 / 仓库 / 镜像...⌘K搜索
注册
博客列表
编程语言

Git 远程仓库操作指南:克隆、推送、拉取与标签管理

Git 远程仓库是分布式版本控制的核心组件,用于代码备份与多人协作。远程仓库基础概念,涵盖 Gitee、GitHub 等平台选择。重点演示克隆仓库、配置 SSH Key、推送与拉取代码等核心操作流程。同时介绍.gitignore 文件配置以忽略敏感信息,以及命令别名设置提升效率。最后讲解标签管理,包括创建、查看、推送及删除标签,确保版本清晰可控。掌握这些技能可实现跨设备开发与高效团队协作。

鲜活发布于 2026/3/26更新于 2026/9/1956 浏览
Git 远程仓库操作指南:克隆、推送、拉取与标签管理

在这里插入图片描述

前言

当你在本地用 Git 完成版本控制后,如何实现代码备份、跨设备开发?答案是 远程仓库。Git 作为分布式版本控制系统,远程仓库不仅是代码的'云端保险箱',更是后续多人协作的基础。但很多初学者会卡在'本地与远程同步'的环节——不知道怎么关联仓库、推送代码报错、拉取后冲突不断。本文结合核心知识点,聚焦远程操作到多人协作前的关键步骤,从远程仓库概念、关联与克隆,到代码推送/拉取、忽略文件配置,再到标签管理,每个操作都附具体命令和场景示例,帮你打通'本地→远程'的数据流链路,为后续多人协作做好充分准备。

一、远程仓库基础:理解分布式协作的核心

1.1 理解分布式版本控制系统

我们目前所说的所有内容(工作区、暂存区、版本库等等),都是在本地!也就是在你的笔记本或者计算机上。而我们的 Git 其实是分布式版本控制系统! 什么意思呢? 可以简单理解为,我们每个人的电脑上都是一个完整的版本库,这样你工作的时候,就不需要联网了,因为版本库就在你自己的电脑上。既然每个人电脑上都有一个完整的版本库,那多个人如何协作呢?比方说你在自己电脑上改了文件 A,你的同事也在他的电脑上改了文件 A,这时,你们俩之间只需把各自的修改推送给对方,就可以互相看到对方的修改了。

在这里插入图片描述

分布式版本控制系统的安全性要高很多,因为每个人电脑里都有完整的版本库,某一个人的电脑坏掉了不要紧,随便从其他人那里复制一个就可以了。 在实际使用分布式管理系统的时候,其实很少在两人之间的电脑上推送版本库的修改,因为可能你们俩不在一个局域网内,两台电脑互相访问不了。也可能今天你的同事病了,他的电脑压根就没打开。因此,分布式控制系统通常也有一台充当'中央服务器'的电脑,但这个服务器的作用仅仅是用来方便'交换'大家的修改,没有它大家也一样干活,只是交换修改不方便而已。有了这个'中央服务器'的电脑,这样就不怕本地出现什么故障(比如运气差,硬盘坏了,上面的所有东西全部丢失,包括 Git 的所有内容)。

1.2 什么是远程仓库?

远程仓库是托管在服务器上的 Git 仓库(如 Gitee、GitHub),与本地仓库的关系可概括为:

  • 本地仓库:仅存于个人设备,适合单人开发时的版本控制;
  • 远程仓库:存于云端,支持多人访问,核心作用是'代码共享'与'数据备份'。

关键优势:分布式设计让每个设备都有完整版本库,即使远程服务器故障,也能从任意本地仓库恢复数据。 常见远程仓库平台:

平台特点适用场景
Gitee(码云)国内访问速度快,支持企业级协作国内团队、个人项目
GitHub全球最大开源社区,资源丰富开源项目、国际协作
GitLab支持私有化部署,权限管理灵活企业内部项目

因为 GitHub 是国外的网站,速度比较慢,所以这里演示的时候我们都使用码云来进行托管代码。

二、远程仓库核心操作:从关联到同步

2.1 创建远程仓库:前置准备工作

在克隆之前,我们首先要在码云上创建一个仓库。

  • 新建远程项目仓库:

在这里插入图片描述

  • 填写基本信息:(设置模板那里可以都先勾上)

在这里插入图片描述

  • 创建成功:

在这里插入图片描述

  • 创建成功后,我们可以对远程仓库进行一个基本设置:开源或者私有:

在这里插入图片描述

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

在这里插入图片描述

2.2 克隆远程仓库:从远程到本地

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

在这里插入图片描述

SSH 协议和 HTTPS 协议是 Git 最常用使用的两种数据传输协议。SSH 协议使用了公钥加密和公钥登录机制,体现了其实用性和安全性,使用此协议需要将我们的公钥放上服务器,由 Git 服务器进行管理。使用 HTTPS 方式时,没有要求,可以直接克隆下来。

  • 使用 HTTPS 方式:
[Lotso@VM-4-4-centos ~]$ git clone https://gitee.com/huang-qiruiqq/git_studying.git
Cloning into 'git_studying'...
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)
Unpacking objects: 100% (7/7), done.
[Lotso@VM-4-4-centos ~]$ ls git_studying test.txt
[Lotso@VM-4-4-centos ~]$ ls -a git_studying/
... .git .gitee README.en.md README.md 
  • 使用 SSH 方式:
[Lotso@VM-4-4-centos ~]$ git clone [email protected]:huang-qiruiqq/git_studying.git
Cloning into 'git_studying'...
The authenticity of host'gitee.com (180.76.198.77)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
ECDSA key fingerprint is MD5:27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,180.76.198.77' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

使用 SSH 方式克隆仓库,由于我们没有添加公钥到远端库中,服务器拒绝了我们的 clone 链接。需要我们设置一下:

第一步:创建 SSH Key。在用户主目录下,看看有没有.ssh 目录,如果有,再看看这个目录下有没有 id_rsa 和 id_rsa.pub 这两个文件,如果已经有了,可直接跳到下一步。如果没有,需要创建 SSH Key:

# 注意要输入自己的邮箱,然后一路回车,使用默认值即可
[Lotso@VM-4-4-centos ~]$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/Lotso/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again:
Your identification has been saved in /home/Lotso/.ssh/id_rsa.
Your public key has been saved in /home/Lotso/.ssh/id_rsa.pub.
The key fingerprint is: SHA256:7yfC1QgkL2eRdSK6IwX8byuPXBJoPcCT5JaOryuFNyI [email protected]
The key's randomart image is: +---[RSA 2048]----+
| .o .oo .|| +.+..+. o || O.o+ .|| + *o.=||..= *=S. o ||E +o . +o.o .||.+ .. .o.o. ||....++...|| .o. oo...o |
+----[SHA256]-----+

顺利的话,我们可以在用户主目录里找到 .ssh 目录,里面有 id_rsa 和 id_rsa.pub 两个文件,这两个就算 SSH Key 的秘钥对,id_rsa 是私钥,不能泄漏出去,id_rsa.pub 是公钥,可以放心地告诉任何人。

[Lotso@VM-4-4-centos ~]$ ls -a .ssh/
... id_rsa id_rsa.pub known_hosts 

第二步:添加自己的公钥到远端仓库。

[Lotso@VM-4-4-centos ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDezcher5w+wG77fpWiuGWo8Mofpl3yDe3vUcCWBRG71WxCKrvCmJt4c5pbH+y+1eG4nvhwG9n/WGZOH5/8rVMrKQfksENGKg5GLbEwx+8CQqgdHDHC0CyHZevRRBx7qHQwlj0TjuyId1IK18cuGPV4F4hOCCS+hkey2Wd+5A/4kLyf6U5JCnEqcbtOvdZXxK3JlnoUI2RZ5nqRJ6l1pFn6m3ZxsILLdCVbMut4MLgD1UB/Y1O6Vu+lcsgRsf3HoDAxkh3j86foJLg7Xr7Mg6XdUotWxQ98VlKxbNASE5fKYJFlMPOmNmtFz0zl+zMLyUVg0+iztkBKgRH5oGlgtQXb [email protected]

这个是我刚刚加的:

在这里插入图片描述

[Lotso@VM-4-4-centos ~]$ git clone [email protected]:huang-qiruiqq/git_studying.git
Cloning into 'git_studying'...
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), done.
[Lotso@VM-4-4-centos ~]$ ls git_studying test.txt
[Lotso@VM-4-4-centos ~]$ ls git_studying/
README.en.md README.md 

done,成功!如果有多个人协作开发,GitHub/Gitee 允许添加多个公钥,只要把每个人电脑上的 Key 都添加到 GitHub/Gitee,就可以在每台电脑上往 GitHub/Gitee 上提交推送了。 当我们从远程仓库克隆后,实际上 Git 会自动把本地的 master 分支和远程的 master 分支对应起来,并且远程仓库的默认名称是 origin。在本地我们可以使用 git remote 命令,查看远程库的信息,如:

[Lotso@VM-4-4-centos ~]$ cd ./git_studying
[Lotso@VM-4-4-centos git_studying]$ pwd
/home/Lotso/git_studying
[Lotso@VM-4-4-centos git_studying]$ git remote origin

或者,用 git remote -v 显示更详细的信息:

[Lotso@VM-4-4-centos git_studying]$ git remote -v
origin [email protected]:huang-qiruiqq/git_studying.git (fetch)
origin [email protected]:huang-qiruiqq/git_studying.git (push)

上面显示了可以抓取和推送的 origin 的地址。如果没有推送权限,就看不到 push 的地址。推送是什么意思呢,我们继续往下看。

三、向远程仓库推送和拉取远程仓库的操作

3.1 向远程仓库推送

本地已经 clone 成功远程仓库后,我们便可以向仓库中提交内容。例如新增一个 file.txt 文件:

# 新建文件
[Lotso@VM-4-4-centos git_studying]$ ls README.en.md README.md
[Lotso@VM-4-4-centos git_studying]$ nano file.txt
[Lotso@VM-4-4-centos git_studying]$ cat file.txt
hello git
# 提交文件
[Lotso@VM-4-4-centos git_studying]$ git add .
[Lotso@VM-4-4-centos git_studying]$ git commit -m "create file.txt"
[master db072d6] create file.txt
1 file changed, 1 insertion(+)
create mode 100644 file.txt 

提交时需要注意,如果我们之前设置过全局的 name 和 email,这两项配置需要和 gitee 上配置的用户名和邮箱一致,否则会出错。或者从来没有设置过全局的 name 和 email,那么我们第一次提交时也会报错。这就需要我们重新配置下了,同样要注意需要和 gitee 上配置的用户名以及邮箱一致,如何配置之前讲过了,在这里就不再赘述。 到这里我们已经将内容提交至本地仓库中,如何将本地仓库的内容推送至远程仓库呢,需要使用 git push 命令。 该命令用于将本地的分支版本上传到远程并合并,命令格式如下:

git push <远程主机名><本地分⽴名>:<远程分⽴名>
# 如果本地分⽴名与远程分⽴名相同,则可以省略冒号:
git push <远程主机名><本地分⽴名>

此时我们要将本地的 master 分支推送到 origin主机的 master 分支,则可以:

[Lotso@VM-4-4-centos git_studying]$ git push origin master:master
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 274 bytes |0 bytes/s, done.
Total 3(delta 1), reused 0(delta 0)
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag ef47a6bd
To [email protected]:huang-qiruiqq/git_studying.git
59ec3c5..db072d6 master -> master 

推送成功!这里由于我们使用的是 SSH 协议,是不用每一次推送都输入密码的,方便了我们推送操作。如果你使用的是 HTTPS 协议,有个麻烦的地方就是每次推送都必须输入口令。 接下来,看看码云远端:

在这里插入图片描述

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

在这里插入图片描述

3.2 拉取远程仓库

从远程获取最新代码并合并到本地,避免本地代码落后导致冲突,常用命令有 git fetch(仅获取不合并)和 git pull(获取并合并):我们这里主要讲讲 git pull,下面的修改操作仅作为演示,实际使用中大家不要在码云上直接去修改内容。

在 gitee 上点击 file.txt 文件并修改它 (新增一行 hello Lotso)

在这里插入图片描述

在这里插入图片描述

此时,远程仓库是要领先于本地仓库一个版本,为了使本地仓库保持最新的版本,我们需要拉去下远端代码,并合并到本地。Git 提供了 git pull 命令,用于从远程获取代码并合并到本地的版本,格式如下:

git pull <远程主机名><远程分⽴名>:<本地分⽴名>
# 如果远程分⽴是与当前分⽴合并,则冒号后⾯的部分可以省略。
git pull <远程主机名><远程分⽴名>

我们来使用一下:

# 拉取远程分支,并与当前分支进行合并
[Lotso@VM-4-4-centos git_studying]$ git pull origin 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), done.
From gitee.com:huang-qiruiqq/git_studying
* branch master -> FETCH_HEAD
Updating db072d6..0d64ce5 Fast-forward
file.txt |1 + 1 file changed, 1 insertion(+)
[Lotso@VM-4-4-centos git_studying]$ cat file.txt
hello git
hello Lotso 

到了这里我们可以发现,拉取成功了~

四、忽略特殊文件以及给命令配置别名

4.1 忽略特殊文件:.gitignore 配置

在日常开发中,我们有些文件不想或者不应该提交到远端,比如保存了数据库密码的配置文件,那怎么能让 Git 知道呢?所以我们在 Git 工作区的根目录下创建一个特殊的 .gitignore 文件,然后把要忽略的文件名填进去,Git 就会自动忽略这些文件了。 不过我们其实也不需要从头写 .gitignore 文件,gitee 在创建仓库时就可以为我们生成,不过需要我们主动勾选一下(有很多种,大家可以按需选择):

在这里插入图片描述

那要是我们创建的时候没有选择这个,在工作区创建一个也是可以的,无论时哪一种方式,最终都可以得到一个完整的 .gitignore 文件,例如我们想忽略以 .so 和 .ini 结尾的所有文件,.gitignore 的内容如下:

# 省略选择模本的内容...
# My configurations:
*.ini
*.so 

在 .gitignore 文件中也可以指定某个确定的文件。 最后一步就是把 .gitignore 也提交到远端,就完成了:

[Lotso@VM-4-4-centos git_studying]$ nano .gitignore
[Lotso@VM-4-4-centos git_studying]$ git add .
[Lotso@VM-4-4-centos git_studying]$ git commit -m "add .gitignore"
[master 97a0741]add .gitignore
1 file changed, 5 insertions(+)
create mode 100644 .gitignore
[Lotso@VM-4-4-centos git_studying]$ git push origin master
Warning: Permanently added the ECDSA host key for IP address '180.76.199.13' to the list of known hosts.
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 329 bytes |0 bytes/s, done.
Total 3(delta 1), reused 0(delta 0)
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag f342e0a2
To [email protected]:huang-qiruiqq/git_studying.git
0d64ce5..97a0741 master -> master 

接着我们就来验证一下 .gitignore 文件的能力,在工作区新置两个文件 a.so b.ini:

[Lotso@VM-4-4-centos git_studying]$ touch a.so b.ini
[Lotso@VM-4-4-centos git_studying]$ git status
# On branch master nothing to commit, working directory clean 

检验 .gitignore 的标准就是 git status 命令是不是说 working tree clean。我们发现 Git 并没有提示在工作区有文件新增,那我们的 .gitignore 就生效了。 但有些时候,你就是想添加一个文件到 Git,但由于这个文件被 .gitignore 忽略了,根本添加不了,那么可以用 -f 强制添加:

$ git add -f [filename]

或者你发现,可能是 .gitignore 写得有问题,需要找出来到底哪个规则写错了,比如说 a.so 文件是要被添加的,可以用 git check-ignore 命令来检查:

[Lotso@VM-4-4-centos git_studying]$ git check-ignore a.so
a.so
[Lotso@VM-4-4-centos git_studying]$ git check-ignore -v a.so
.gitignore:5:*.so a.so 

Git 会告诉我们,.gitignore 的第 5 行规则忽略了该文件,于是我们就可以知道应该修订哪个规则。 还有些时候,当我们编写了规则排除了部分文件时,例如:

# 排除所有.开头的隐藏⽂件:.* 

但是我们发现 .* 这个规则把 .gitignore 也排除了。虽然可以用 git add -f 强制添加进去,但是还是有点别扭,这个时候我们可以单独添加一条额外规则:

# 排除所有.开头的隐藏⽂件:.*
# 不排除.gitignore
!.gitignore 

把指定文件排除在 .gitignore 规则外的写法就是 ! + 文件名,所以,只需要把例外文件添加进去即可。

4.2 给命令配置别名

在我们使用 Git 期间,有些命令敲的时候太长了很麻烦,我们的 git 支持对命令进行简化!比如将 git status 简化为 git st,对应的命令为:

[Lotso@VM-4-4-centos git_studying]$ git config --global alias.st 'status'
[Lotso@VM-4-4-centos git_studying]$ git st
# On branch master nothing to commit, working directory clean 

我们再来配置一个 git lpa 让其达到 git log --pretty=oneline --abbrev-commit 的效果

[Lotso@VM-4-4-centos git_studying]$ git log --pretty=oneline --abbrev-commit
97a0741 add .gitignore
0d64ce5 update file.txt.
db072d6 create file.txt
59ec3c5 Initial commit
[Lotso@VM-4-4-centos git_studying]$ git config --global alias.lpa 'log --pretty=oneline --abbrev-commit'
[Lotso@VM-4-4-centos git_studying]$ git lpa
97a0741 add .gitignore
0d64ce5 update file.txt.
db072d6 create file.txt
59ec3c5 Initial commit 

不过,个人还是不推荐大家现在去使用它,等大家工作了,再去简化自己的工作吧,目前所有的命令都要手动完成,尽快适应 Git。

五、标签管理:给重要版本'打标记'

标签(tag)是对某次提交 (commit) 的别名(如 v1.0),比复杂的 commit id 更易记忆,适合标记发布版本:

5.1 创建标签

在 Git 中打标签非常简单,首先,切换到需要打标签的分支上,我这里看了下只有 master

[Lotso@VM-4-4-centos git_studying]$ git branch
* master 

然后,敲命令 **git tag [name]** 就可以打一个新的标签,并用 git tag 查看所有标签:

[Lotso@VM-4-4-centos git_studying]$ git tag v1.0
[Lotso@VM-4-4-centos git_studying]$ git tag v1.0 

默认标签是打在最新提交的 commit 上的。那如何在指定的 commit 上打标签呢?方法是找到历史提交的 commit id,然后打上就可以了,示例如下:

# 历史记录
[Lotso@VM-4-4-centos git_studying]$ git log --pretty=oneline --abbrev-commit
97a0741 add .gitignore
0d64ce5 update file.txt.
db072d6 create file.txt
59ec3c5 Initial commit
# 对 update file.txt. 这次提交打标签
[Lotso@VM-4-4-centos git_studying]$ git tag v0.9 0d64ce5
[Lotso@VM-4-4-centos git_studying]$ git tag v0.9 v1.0 

注意,标签不是按时间顺序列出,而是按字母排序的。 可以用 git show [tagname] 查看标签信息。

[Lotso@VM-4-4-centos git_studying]$ git show v1.0
commit 97a07417c4ad9b4d94001dfce01b954dfec4c4a2
Author: Lotso-1 <[email protected]>
Date: Wed Nov 5 16:39:08 2025 +0800
add .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644 index 0000000..51e9946
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+# 省略选择模本的内容
+
+# My configuration:
+*.ini
+*.so 

Git 还提供可以创建带有说明的标签,用 -a 指定标签名,-m 指定说明文字,格式为:

git tag -a [name] -m "XXX"[commit_id]

另外,打完标签之后,可以使用 tree .git 命令查看一下你的本地库有啥变化,帮助理解。

[Lotso@VM-4-4-centos git_studying]$ tree .git
.git
|-- branches
|-- COMMIT_EDITMSG
|-- config
|-- description
|-- FETCH_HEAD
|-- HEAD
|-- hooks
|   |-- applypatch-msg.sample
|   |-- commit-msg.sample
|   |-- post-update.sample
|   |-- pre-applypatch.sample
|   |-- pre-commit.sample
|   |-- prepare-commit-msg.sample
|   |-- pre-push.sample
|   |-- pre-rebase.sample
|   `-- update.sample
|-- index
|-- info
|   `-- exclude
|-- logs
|   |-- HEAD
|   `-- refs
|       |-- heads
|       |   `-- master
|       `-- remotes
|           `-- origin
|               |-- HEAD
|               `-- master
|-- objects
|   |-- 0d
|   |   `-- 64ce57c58947129e9d7582b04efcecd5725596
|   |-- 25
|   |   `-- a78b7a089ea9102dd56f57073ee355e90e1a7
|   |-- 51
|   |   `-- e9946bd4567839abdf1841f9f8d70f4f53768
|   |-- 7f
|   |   `-- 11fc07051f8be46a25052dbbaa00747982411
|   |-- 81
|   |   `-- 24db872ed89fcc3cd4ccf22026606
|   |-- 8d
|   |   `-- 0e41234f24b6da002d962a26c2495ea1a4cf38
|   |-- 97
|   |   `-- a07417c4ad9b4d94001dfce01b954dfec4c4a2
|   |-- 9b
|   |   `-- a04ab27474028da63e6d3ad701b533ac34866a
|   |-- db
|   |   `-- 072d6af64a7cc40302fcdf51e074158ea4cf38
|   |-- info
|   |   `-- pack
|   |       `-- pack-2414a943109cfa2f62f9f9d8e3e1ac4114c225e8.idx
|   |           `-- pack-2414a943109cfa2f62f9f9d8e3e1ac4114c225e8.pack
|-- ORIG_HEAD
|-- packed-refs
`-- refs
    |-- heads
    |   `-- master
    |-- remotes
    |   `-- origin
    |       |-- HEAD
    |       `-- master
    `-- tags
        |-- v0.9
        `-- v1.0
25 directories, 38 files 

5.2 操作标签

如果标签打错了,也可以删除:

[Lotso@VM-4-4-centos git_studying]$ git tag v0.9 v1.0
[Lotso@VM-4-4-centos git_studying]$ git tag -d v0.9
Deleted tag 'v0.9'(was 0d64ce5)
[Lotso@VM-4-4-centos git_studying]$ git tag v1.0 

因为创建的标签都只是存储在本地,不会自动推送到远程。所以,打错的标签可以在本地安全删除。 如果要推送某个标签到远程,使用命令 git push origin <tagname>

[Lotso@VM-4-4-centos git_studying]$ git push origin v1.0
Warning: Permanently added the ECDSA host key for IP address '180.76.198.225' to the list of known hosts.
Total 0(delta 0), reused 0(delta 0)
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag e241f4a8
To [email protected]:huang-qiruiqq/git_studying.git
* [new tag] v1.0 -> v1.0 

此时,查看远端码云,看到了标签已经被更新,非常完美~

在这里插入图片描述

当然,如果你本地有很多标签,也可以一次全部推送到远端:

[Lotso@VM-4-4-centos git_studying]$ git push origin --tags

如果标签已经推送到远程,要删除标签就麻烦一点,先从本地删除:

[Lotso@VM-4-4-centos git_studying]$ git tag v1.0
[Lotso@VM-4-4-centos git_studying]$ git tag -d v1.0
Deleted tag 'v1.0'(was 97a0741)

然后,从远程删除,删除命令也是 push,但是格式如下:

[Lotso@VM-4-4-centos git_studying]$ git push origin :refs/tags/v1.0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 74447f86
To [email protected]:huang-qiruiqq/git_studying.git
- [deleted] v1.0 

在码云上查看确实删除了

在这里插入图片描述

结语

Git 远程操作的核心是'数据同步'—— 通过 push 和 pull 实现本地与远程的双向流转,通过.gitignore 和标签管理保证代码整洁与版本清晰。掌握这些操作,不仅能实现单人跨设备开发和代码备份,更能为后续多人协作打下坚实基础。

目录

  1. 前言
  2. 一、远程仓库基础:理解分布式协作的核心
  3. 1.1 理解分布式版本控制系统
  4. 1.2 什么是远程仓库?
  5. 二、远程仓库核心操作:从关联到同步
  6. 2.1 创建远程仓库:前置准备工作
  7. 2.2 克隆远程仓库:从远程到本地
  8. 注意要输入自己的邮箱,然后一路回车,使用默认值即可
  9. 三、向远程仓库推送和拉取远程仓库的操作
  10. 3.1 向远程仓库推送
  11. 新建文件
  12. 提交文件
  13. 如果本地分⽴名与远程分⽴名相同,则可以省略冒号:
  14. 3.2 拉取远程仓库
  15. 如果远程分⽴是与当前分⽴合并,则冒号后⾯的部分可以省略。
  16. 拉取远程分支,并与当前分支进行合并
  17. 四、忽略特殊文件以及给命令配置别名
  18. 4.1 忽略特殊文件:.gitignore 配置
  19. 省略选择模本的内容...
  20. My configurations:
  21. On branch master nothing to commit, working directory clean
  22. 排除所有.开头的隐藏⽂件:.*
  23. 排除所有.开头的隐藏⽂件:.*
  24. 不排除.gitignore
  25. 4.2 给命令配置别名
  26. On branch master nothing to commit, working directory clean
  27. 五、标签管理:给重要版本“打标记”
  28. 5.1 创建标签
  29. 历史记录
  30. 对 update file.txt. 这次提交打标签
  31. 5.2 操作标签
  32. 结语

更多推荐文章

查看全部
  • 流批一体架构下时序数据库选型:Apache IoTDB 能力解析与对比
  • PyCharm 调用 AI 模型 API 辅助编程指南
  • 基于 Z-Image-Turbo 的本地 AI 绘画部署:16GB 显存支持与双语提示
  • ROS 导航:基于 mpc_local_planner 的高效避障与参数调优
  • AI 辅助撰写高质量文献综述:全流程操作指南与提示词
  • SkyWalking - .NET / C++ / Lua 探针现状与社区支持
  • GitHub Copilot 兼容 API 方案:copilot-api 使用指南
  • Java 使用 Apache POI 导出 Excel 文件
  • JTAG 接口实测波形与基础时序分析
  • GitHub 日榜精选:AI Agent、Web 分析与开发工具
  • RTX 4090 加速国产 AIGC 视频生成:腾讯混元与阿里通义万相开源模型
  • 无人机 AI 算法全景图:7 大场景 50+ 算法详解
  • Kotlin 基础:拒绝语法噪音
  • HTML 与 CSS 网页美化技巧
  • Flutter eip55 库在鸿蒙系统的适配与以太坊地址校验实战
  • 多进制奇偶校验检查器(HTML+CSS+JS 纯前端实现)
  • Faster-Whisper 本地部署:实现实时语音转文本实战指南
  • Flutter 三方库 bavard 在 OpenHarmony 上的适配实践:语义化消息协议与机器人逻辑
  • 基于 CentOS 的 Kubernetes 集群搭建实战
  • 大模型在智能客服领域的应用现状与最佳实现路径

相关免费在线工具

  • Base64 字符串编码/解码

    将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online

  • Base64 文件转换器

    将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online

  • Markdown转HTML

    将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online

  • HTML转Markdown

    将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML转Markdown在线工具,online

  • JSON 压缩

    通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online

  • JSON美化和格式化

    将JSON字符串修饰为友好的可读格式。 在线工具,JSON美化和格式化在线工具,online