Git branch from a remote branch tag

Viewed 32

Here is my setup

  1. Remote named upstream points to the the branch where tag exists.
  2. Remote named origin points to my fork.

I want to create a branch under origin that is even with the upstream tag. Make some changes to this newly created branch and raise a pull request to the upstream.

I am currently checked out on a branch under origin.

Performed the following operations based on this answer : https://stackoverflow.com/questions/15043450/git-branch-from-remote-tag

git fetch upstream <TAG_NAME>

1.

git checkout <TAG_NAME> -b <NEW_BRANCH>

fatal: '<TAG_NAME>' is not a commit and a branch '<NEW_BRANCH>' cannot be created from it

2.

git checkout tags/<TAG_NAME> -b <NEW_BRANCH>

fatal: 'tags/<TAG_NAME>' is not a commit and a branch '<NEW_BRANCH>' cannot be created from it

3.

git checkout upstream <TAG_NAME> -b <NEW_BRANCH>

fatal: Cannot update paths and switch to branch '<NEW_BRANCH>' at the same time.

1 Answers

Try the new git switch command instead

git switch -c newBranch tagName

This assumes that git tag -l does list the tag you want after a git fetch --tags upstream.

Related