Actual commands for cutting release branches in GitFlow
Asked Answered
E

2

6

New to git and trying to learn GitFlow. With GitFlow, every so often you cut a release branch off of the develop branch, so that you can isolate a subset of new changes and deploy them to some staging/nonprod environment. But nowhere can I actually find solid documentation on what the proper procedure is (command-wise) for cutting these release branches. Is it:

git checkout develop
git pull
git checkout -b release/1.1.3
git add .
git commit -m "Cutting release branch for v1.1.3."
git push

Or is it:

git checkout develop
git pull
git checkout -b release/1.1.3
git push origin release/1.1.3

Or is it something else? And why?!

Emelineemelita answered 16/12, 2017 at 3:51 Comment(2)
Well, running git add . after git checkout doesn't really make any sense (because you haven't made any changes, right?). So once you get rid of the git add and the subsequent commit, your two procedures above are the same.Grays
Thanks @Grays but that leaves me a bit confused, mind providing a concrete answer? I mean, do I do git push or git push origin release/1.1.3, etc.?Emelineemelita
G
7

First to make sure you are develop branch and it is up to date:

 git checkout develop
 git pull

If you run:

git checkout -b release/1.1.3
git push

You will probably receive the error:

fatal: The current branch release/1.1.3 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin release/1.1.3

Because you have created a new branch locally, so it has no associated upstream tracking branch until you tell it what it should be tracking. So you need to be explicit about to where you want to push it, as in:

git push origin release/1.1.3
Grays answered 16/12, 2017 at 4:19 Comment(0)
E
2

I can't comment on the above answer because I don't have 50 reputation...BUT I just wanted to add that the --set-upstream (or just -u) flag should also be included so you don't have to repeatedly specify your desired upstream branch any time you want to push from your local to a remote branch. If you run this once:

git push -u origin release/1.1.3

Then in the future if you're on branch release/1.1.3 you can just run

git push

and git will remember that you set your upstream branch and push to the same spot.

Enriqueenriqueta answered 1/9, 2021 at 21:49 Comment(1)
Upvoted your answer so that you get points to comment soon.Maxon

© 2022 - 2024 — McMap. All rights reserved.