简体   繁体   中英

What's the best way to move my origin/master to a new branch?

I am looking at starting a v2 of my code and wanted to archive my v1 code in the same repo at a new branch so that I could have a fresh start in my repo at the origin.

What's the best practices for this or approaches for this?

Best and easiest way to have multiple versions (Either for releasing a stable version or changing other things in next versions) is to use git tag command

  • the Git command line, or
  • GitHub's web interface.

Creating tags from the command line

To create a tag on your current branch, run this:

git tag <tagname>

If you want to include a description with your tag, add -a to create an annotated tag :

git tag <tagname> -a

This will create a local tag with the current state of the branch you are on. When pushing to your remote repo, tags are NOT included by default. You will need to explicitly say that you want to push your tags to your remote repo:

git push origin --tags

From the official Linux Kernel Git documentation for git push :

 --tags

All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.

Or if you just want to push a single tag:

git push origin <tag>

See also How do you push a tag to a remote repository using Git? for more details about that syntax above.

I would create a new release, using the GitHub cli gh tool gh release create

gh release create v1.0.0 --notes "v1"

That would create/push the tag for you, allowing you to go-on on your main branch for v2.

That means: You don't need origin/master to a new branch right away, only a tag from which you can create a v1_fixes branch later, if you have to maintain v1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM