当前位置:   article > 正文

Git通过tag创建分支并推送到远程_git tag 推送到远程

git tag 推送到远程

1:建立远端仓库

可在github,或者gitee上建立,如下我是在gitee:
在这里插入图片描述

2:克隆到本地

git clone克隆,具体略。

3:打tag

$ git tag -a 'testtag-v1' -m '测试打tag'

JHP+Administrator@jhp MINGW64 /D/test/testtag (master)
$ git tag
testtag-v1
  • 1
  • 2
  • 3
  • 4
  • 5

-a:add代表添加
-m:comment,注释

4:将tag推送到远端

格式git push <远端仓库名,默认为origin> 本地仓库名称:远端仓库名称 --tags

$ git push origin master:master --tags
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 175 bytes | 175.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/dongsir2020/testtag.git
 * [new tag]         testtag-v1 -> testtag-v1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

推送完毕后,就会在远端仓库生成一个tag,如下图:
在这里插入图片描述

5:通过tag打新分支

$ git checkout -b testtag-v1-new-branch testtag-v1
Switched to a new branch 'testtag-v1-new-branch'
  • 1
  • 2

6:将新分支推送到远端

$ git push origin testtag-v1-new-branch:testtag-v1-new-branch
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
remote: Create a pull request for 'testtag-v1-new-branch' on Gitee by visiting:
remote:     https://gitee.com/dongsir2020/testtag/pull/new/dongsir2020:testtag-v1-new-branch...dongsir2020:master
To https://gitee.com/dongsir2020/testtag.git
 * [new branch]      testtag-v1-new-branch -> testtag-v1-new-branch
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

推送成功后将会在远端生成仓库,如下图:
在这里插入图片描述

7:将本地分支追踪到远端分支

如果是设置,当前本地分支没有追踪到任何远端分支,如下:

$ git branch -vv
  master                9940582 [origin/master] Initial commit
* testtag-v1-new-branch 9940582 Initial commit
  • 1
  • 2
  • 3

设置追踪:

$ git push --set-upstream origin testtag-v1-new-branch:testtag-v1-new-branch
Everything up-to-date
Branch 'testtag-v1-new-branch' set up to track remote branch 'testtag-v1-new-branch' from 'origin'.
  • 1
  • 2
  • 3

再次查看追踪情况:

$ git branch -vv
  master                9940582 [origin/master] Initial commit
* testtag-v1-new-branch 9940582 [origin/testtag-v1-new-branch] Initial commit
  • 1
  • 2
  • 3

可以看到本地分支testtag-v1-new-branch,已经追踪到远端分支origin/testtag-v1-new-branch了,这之后当我们使用git pull,git push时就会默认从追踪的远端分支拉取和推送代码了。当然也可以通过指定远端分支的方式显示的推送或者是拉取,如下就是将本地分支testtag-v1-new-branch,推送到远端分支origin/master

$ git push origin testtag-v1-new-branch:master
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/dongsir2020/testtag.git
   9940582..a85d924  testtag-v1-new-branch -> master
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/914104
推荐阅读
相关标签
  

闽ICP备14008679号