hey i'm cameron mckenzie at cameron mcnz on twitter and i want to talk to you about git flow
in it specifically how to run git flow in it and get started with git flow and then if you got the
time i wanted to real quickly show you how to go through master to develop to feature back to
develop into release and back to master and show you how after you've done a git flow in it how
easy it is to go through the git flow workflow so step one of working with git flow is issuing and
get flow in it call so i've got a little folder called my git flow i've also got a nice little
git flow diagram to the right which i thought we might work through if you've got the time but
before you can do any of that you've got to issue the get flow init command that's where everything
starts now maybe it doesn't start there maybe you actually have to install git first and then make
sure git flow is installed as well but let's just say you've got that done and you want to start
with git flow while get flow in it is the thing to do now right when it starts off it's going to ask
you how you want to set up git flow so it says you know what's the name for production releases you
can just click enter here and accept the defaults and if you click enter it won't leave it blank
it'll leave it as master you know the the proper terminology nowadays is maine not to use master
to to kind of respect some of the historical indignities associated with that word so you know
i'm going to set that as main and i also you know i don't like the develop branch i like to develop
mint branch so you can type that in there if you want so i've done a couple of little changes here
but you know you shouldn't change these things so you know the more you change it the more confusing
it'll be to other people that jump on the project so for i'm just going to click enter for feature
the bug fix branch will be bug fixed the release branch will be release hotfix hot fix support
support and life is good now notice it asks for a tag prefix i'm not going to have a tag prefix
so i'll just accept the default which is nothing and then i can explicitly state what my tag is
going to be and you can see here it's found out where the hooks directory of my git installation
is and i think that looks good it just needs to get hooked it needs the hooks in order for
git flow and the git flow extension to work okay well there you go that is git flow up
running and initialized and you'll notice it asks me for all of these different branches here so
the the feature branches where you do development you can see it down here
and that's where you have all of your topic branches off of the development
branch itself so that's where you work on features that eventually get pushed into the develop branch
the bug fix branch is branches off the development branch but of course it's for just that a fix
as opposed to a feature or feature enhancement releases you see that over here when you're done
in development and you actually want to release some code back into the master branch and make it
publicly available you first create a release and then that gets pushed to master there's hotfix as
well i don't have the hotfix here but if there's a problem in master you branch off to a hotfix
and then you push it back in in a giant hurry um and then there's support so if you've got an old
version and you want to have a support line for it you can use that so that's kind of how those
things work now a couple of things to note notice right off the bat it's asking me about all these
branches but if i do a git branch dash a now how many branches do you think will be there well if
you said two you've got the right answer the only ones that are available to start are development
and main that actually catches some people off guard because they think hey didn't we just
create all these branches here well no you didn't all we did was sort of create some organizational
subfolder type of structure in order to keep track of the different branches but no actually
we didn't create branches the only one created by default are development right there and main
so if we took a look at our application right now that's where we are we've got the master and the
develop branch so of course if you want to do some development you don't do development directly on
the develop branch you want to work in an isolated branch where you can play around and experiment a
little bit and in order to do that well you create a feature branch so i've only got two branches
here i need to create a feature branch in order to i issue the git flow feature start command
and provide a branch name so i'm going to paste a little command in there git flow feature start
and uh put a name of a branch could be any branch that you want i'll just call mine feature branch
because i'm not very creative that creates that branch but you get branch dash a you'll notice
that we've got a new branch called feature branch and you'll notice as well that i've been switched
onto the feature branch and what do you do here well i don't know maybe touch feature.html i'll
just create a file called feature add it to the git repository give it a commit
now we're feature complete and i guess we've moved over right here right so before we were
right here we branched off that created a commit now we've done one more commit
we're right here if i do get ref log you can kind of see that neat commit history here
i guess i could do another commit and that would take me right here but i'm not going to right so
let's just leave that let's say we're now feature complete what do you do at the feature complete
point well what you say is you say hey get flow you know what i'm done with this branch i'm done
with this feature branch they say git flow feature finish that feature branch that i just created and
what's going to happen is git flow is going to take that feature branch and then merge it
back into develop it's not only going to merge it back into develop but it's also going to delete
it so if i do a git branch dash a at this point in time you notice that i no longer have that feature
branch anymore it's gone it's been deleted so see get workflow get git flow is not only helping me
develop branches and and enforce some good git branching strategies but it's also doing some
cleanup as well getting rid of that branch when it's no longer needed and pushing it in to develop
okay so what do you do once your feature complete well then you start thinking about doing a
release and we don't have any releases yet so if i do a git tag dash a you'll see that we don't have
git sorry i always do that incorrectly it's get branch dash h get tag l and you'll notice that we
don't have any tags we don't have any releases yet so what we'd like to do is like to take
this feature complete point and create a release branch you don't go from develop right into master
should have a little bit of a release procedure and so in order to do that we say hey git flow
i want to do a release let's start the release process with version 0.1.0 that now creates a
release branch so if i do get branch dash a not get branch dash l you'll see that i now have the
release branch and that's where i am i'm on the release branch currently thus the asterisk next to
release now what do you do here well potentially you might have you know you might find a bug in
the your last minute work so you know you might you know add a quick fix so get so touch
releasefix.html get add git commit dash m release fixed
and then all of a sudden you know we're here we've done all the last minute testing there's
nothing else to to go into this release and then what we want to do is push it
into master so in order to do that well what did we do we did the git flow release
start now we do the get flow release finish 0.1.0
and now what happens is this release branch right here this commit at the tip of the release branch
it gets merged into master and you can see here we're going to
merge this into well main because i've renamed git master to main now when it when you do a
commit it brings up this editor and you have to give it a message also it creates a tag
and so we're going to create a tag zero one zero we have to provide a tag message so
i'll do a very creative tag message where it just says tag message and close here
and of course finally we're also going to merge into develop so we actually have a
commit as well for merging into developing a chance to put a commit message in there
and then finally if i do get branch dash a you'll notice that i've only got two
branches i'm currently on development if i do ls you notice that both the feature and the
release fix that were created the feature was created there the release fix was created there
those two files are now in the development branch and if i do a git checkout you can
actually see i've got those in main as well but here's the cool thing if i do a git tag dash
l not dash a you'll notice that a tag has been applied as well and if you were to actually go in
and inspect what happens when you do the git flow release finish you'd see that it says it makes a
recursive merge to main it makes a recursive merge to development and then finally it does a tag
does it mention the tag in there i don't see the mention of the tag but i tell you that it does it
and then finally it deletes the branch that was associated with the release so when we come down
here and we say yeah it does say that we tagged it right there when we do a git branch dash a you
can see that we no longer have that release branch and so what we did there was we started off with
a git init that gave us master and develop we then moved on to feature and did a commit there
we thought we were feature complete so we moved into the we merged into the develop
branch again from the develop branch we wanted to create a release branch we made a little fix to
the release branch and then finally when we were done we merged that release branch into main and
of course any little fixes that we made here we want to make sure that development gets them as
well there's no point making a fix here putting it into master not putting it into development
and then the next time we do a release branch and put into master we've got the same problem again
so when we release that branch when we take that release branch and put it into
master it also gets pushed over it to develop as well and then when all that's done that branch
is deleted this branch was deleted before and all we've got left are just these two handsome
little branches in which we can continue to do development and there you go that's how
the get init works and that kind of gives you a quick round trip of working with master develop
feature and release branches and there you go that's how easy it is to work with git flow with
the init command now if you enjoyed that tutorial i want you to head over to the serverside.com i'm
the editor-in-chief over there and you can get all sorts of great information on git git flow
enterprise software development in general if you're interested in my personal antics
you can always follow me on twitter at cameronmcnz and subscribe on the youtube