Search code examples
gitbranchfork

git create local branch for a forked upstream tag


I've been trying to find a way to create a local branch that starts from a tag on an upstream repo I've forked and haven't found anything that helps.

I have the upstream master on a master branch locally but I'm not sure what I need to do to branch the upstream tag.

I've tried:

git branch upstream/master tagname
git branch master tagname
git branch upstream tagname

and none of those worked. Thanks.


Solution

  • If the tag is fetched (your master reflects upstream/master)

    git checkout -b aNewBranch aTagName
    

    You need to make sure you have fetched the tags first.
    That means git fetch upstream and then git fetch upstream --tags

    If you want to fetch only one tag (instead of all tags from upstream):

    git fetch upstream refs/tags/aTagName:refs/tags/aTagName
    

    Note: with Git 2.23 (Q3 2019), that would use the new command git switch:

    git switch -c aNewBranch aTagName