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

1:建立远端仓库

可在github,或者gitee上建立,如下我是在gitee:
Git通过tag创建分支并推送到远程_第1张图片

2:克隆到本地

git clone克隆,具体略。

3:打tag

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

JHP+Administrator@jhp MINGW64 /D/test/testtag (master)
$ git tag
testtag-v1

-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

推送完毕后,就会在远端仓库生成一个tag,如下图:
Git通过tag创建分支并推送到远程_第2张图片

5:通过tag打新分支

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

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

推送成功后将会在远端生成仓库,如下图:
Git通过tag创建分支并推送到远程_第3张图片

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

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

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

设置追踪:

$ 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'.

再次查看追踪情况:

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

可以看到本地分支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

你可能感兴趣的:(git,git)