Friday, November 22, 2013

How to Create a New Local Branch from Existing Remote Tag


  1. Make sure all the remote references are downloaded. I.e. use:

    $ git fetch
  2. If there's any update, something like this should appear after git fetch:

    $ git fetch
    remote: Counting objects: 153, done.
    remote: Compressing objects: 100% (49/49), done.
    remote: Total 97 (delta 58), reused 87 (delta 48)
    Unpacking objects: 100% (97/97), done.
    From github.com:myproject/awesomewebsite
     + 22e503c...5e0ce5a maint      -> origin/maint  (forced update)
     ... something-something ...
     * [new tag]         1.3.84.7   -> 1.3.84.7
    From github.com:myproject/awesomewebsite
     * [new tag]         1.4.20.6   -> 1.4.20.6
  3. Create the new branch in the form:

    $ git checkout -b <new branch name> <tag>

    For example, creating the new branch feature/awesomesauce from tag 1.4.20.6:

     $ git checkout -b feature/awesomesauce 1.4.20.6
If your repository is not updated (step 1), and it does not yet have the reference to the tag, Git will complain like so:

$ git checkout -b feature/awesomesauce 1.4.20.8
fatal: Cannot update paths and switch to branch 'feature/awesomesauce' at the same time.
Did you intend to checkout 'myproject/1.4.20.8' which can not be resolved as commit?


P.S. : This is shown using Linux Terminal/Shell