📺 Develpreneur YouTube Episode

Video + transcript

Versions and Branches in Git

2023-05-30 •Youtube

Detailed Notes

This is an overview from one of our free, introductory classes (https://school.develpreneur.com/p/free_courses).

You can find out more through our online classes at https://school.develpreneur.com and register for free. Registration will add you to our email list and you will periodically receive coupons for courses as well as notifications of the latest releases.

Transcript Text
thank you
[Music]
we are going to talk about in this
lesson something is very common it's
called git git and it is for Version
Control and
the key to good version control though
is that you have a version and branching
strategy if all you're doing is using
Version Control to effectively save
backups of your your files of your
source code that's not a bad thing it's
good to have those it's good to be able
to return to a point in time however
once you have anything beyond one
developer working on your code
then things like and once you deploy
your code it's very valuable to have a
way to get to that version that you
deployed
because usually things will carry on and
you'll do maintenance and things like
that and then also how do I branch which
is even more important because if you've
got more than one developer how do you
which is basically what branching solves
how do you have multiple developers
working in different areas of the
application and not have them step on
each other's toes while they're doing
the coding
that is where your branching strategy is
going to come in
now with your versioning and your
branching the key is to be intentional
this is something that again you know if
it's just one developer in their own
little repository it doesn't matter but
once you get to three 10 developers more
it is crucial that you have a strategy
and that is documented so that people
can know what that strategy is and
actually you also need to have buy-in
from your developers however that is it
doesn't mean they have to be part of the
design of it but when you push that
forward when you document it and say
this is our programming standard This Is
How We Do Version Control there should
be something that is a you know holding
keep people accountable so that they do
that so that they follow those processes
now the goal with our versioning and our
branching really is to easily merge and
reproduce a path of changes so those are
two things we want to be able to easily
merge changes
but we also want to be able to if we
need to go back and reproduce how did we
get to a certain point in time of of a
release or a you know a maybe not a
released version but maybe a tag or a
label or something like that that is a a
milestone of some sort
and now we I mentioned just now we you
have tags also that are available what
you can do is you can use a tag to
essentially be like a bookmark for a
place in time or a milestone or key
features it is not uncommon for tagging
strategy to be part of branching
inversioning so when you create a
version
instead of it being some
you know uuid or not very human friendly
name it has a tag that's something like
you know version 1.0 beta what version
1.0 Beta release to something like that
so that when somebody's looking at the
tags they can fairly quickly map that
back to whatever that release is or
Milestone was that they wanted
a good example would be spreads
you may if you're using agile approach
and you're essentially deploying or
close enough to it deploying at each
Sprint then maybe each tag is going to
be you know Sprint one Sprint two Sprint
three and it may be more you know have a
little more information to it for that
but you may not need it sometimes people
are going to use dates things like that
but some way to point back and say if
I'm looking at all of the code changes
and commits where do I go to reproduce
this thing that we had at this time
now
branching typically
is going to be based on some sort of a
release
and really and and people can change
this up but it's by that I mean is by
release a stable version of code
so when you've got you know version 1.0
so you've got code that works that means
that it's you're comfortable with it
it's gone through its tests it's been
you know blessed by QA or whoever it is
so you know you have at that point
something that quote works
that is a great basis for a branch
because then what happens is you've got
these branches that are based on usually
adding functionality so you have release
1.0 and let's say you have a branch that
is adding security and you have another
branch that is adding back-end
integration
those two things are separate enough
but they need to have that stable
Foundation to work with
and now you're going to come back later
once the work is done on those and merge
those things back in
typically what's going to happen is you
will branch and then you will mer and if
you think of it from a like a tree
branch
is that you've got your main I say trunk
and you have a branch that comes off of
that
and then you have another branch that
comes off of that and we'll call that
Branch two and then you have another
branch that comes off a branch two
that's Branch three but when you merge
what you want to do is you want to
basically push the code from Branch
three all the way out on that little
thing into Branch two and then into
Branch one and then back into the trunk
so that you basically merge your way
back into where the branches came from
it's sort of like how do you find your
way back home if you go out and you know
you start going in a direction and you
turn left and then you turn right and
you turn left to right or whatever you
every time you make a decision
then in order to get back you have to
come back to those decision points to
walk your way back to your home
may seem a little bit confusing but
basically what you do is you branch
and you say okay I'm on a stable
section of code I'm branching off of
that I'm going to do stuff based on that
stable section and then I'm going to
come back when I'm done and I'm going to
merge back into that stable because it
should be if I do it right my stable
changes with that stable Foundation
equals stable foundation with the new
feature now
that can be a challenge because if I'm
working on something that's stable for
me and another developer is working on
something and it's stable for them but
our things have some sort of conflict
then when we merge there's going to be a
conflict with the merge but that's okay
in a sense I mean yes it's going to
require work but what it does is it
means that we know where the conflicts
are we know that we both had this
Foundation that worked and so we can
actually track our changes and figure
out where do we make our changes
and then really if we need to can almost
line by line walk through those to
figure out how to merge those things
back and then once you merge and you
have those things now back into a solid
working Foundation Branch or actually
not even Brent like trunk or Maine
you know Main Branch if you want to call
it that or release branch
then you can tag it
and now I talk about release branches is
sometimes what happens is you have
something that would be production
and then off of that you're going to
Branch you say okay we're going to go do
some development well
at some point that development
maybe that's going to have a branch and
you're going to or a tag or something
along those lines where it's like okay
we're going to release this to QA but
then we're going to specifically be
changing those things in the QA Branch
as opposed to our development branch and
we'll eventually merge those and then we
want to merge to production we'll have
to merge our way back down to production
so it's
it's not the easiest thing to see
sometimes but if you just think about it
as the branches are going to get bigger
and bigger and wider and wider and
there'll be more branches but as you
merge then you're coming you're
essentially in a way traveling back down
those branches to get yourself down to
that single master or trunk
now branching I've talked about a couple
different ways to do it but I want to
talk about the one way that I found that
is very common is it is a branch per
ticket or per bug so if there's a
feature if there's a bug that needs to
be fixed and you create a branch
you know what the branch is the
developer working on it does or changes
and then they merge it back so you what
you do and this is for your Pros is that
when you do when you handle this
approach the changes tend to be small
there's not a lot of changes usually
that are made which means that when you
merge it back merging is going to be
more likely to be successful and less of
a headache
now once you do that it's the con is it
now every time you're get a bug or a
ticket or task you've got to split off
you've got to create your branch you've
got to make sure the developers you know
knows what branch they're on and then
there's got to be a merge back and then
eventually merge that back and you can
end up having a lot of branches but you
can merge and prune so you can go to a
point where you say hey once we get to
this point once we get to this bug being
fixed when we're going to merge it back
we know we're not going to need that
Branch anymore so we're going to merge
back and then that Branch just appears
and so in this case you maybe have a lot
of branches but they end up disappearing
because you're cleaning them up as you
go
and now it's the same thing
you may want to do that and have
branches so that you can go into you
know version 2.0 or 3.0 so that you
would go you know release version 2.0
but if there were bugs to be fixed that
were in 1.0 you could always work off of
that branch and then have a you know 1.1
release even after 2.0 was even released
maybe even way after it was released
but if you do this per ticket bug it
tends to keep it pretty
essentially pretty close to the branch
that you're working on you know saying
assuming it's like a you know a version
Branch or development versus maybe
staging or production the nice thing
about this is it's it's very it's gonna
be very focused and so it's easy to just
you know pop out do a branch make your
fix
test it specifically a lot of times
because and then the merge you can test
very specifically because you're not
having to you didn't touch a lot of
stuff
the tests that you used on the on the
merging or you know as you branched and
fixed it
those tests should be effectively be
able to be added to your overall testing
strategy verify it and move on
so there's some there's quite a few Pros
to taking this approach the cons are
really usually more about people just
not being as comfortable creating
branches and merging and things like
that and it's it's really more of a
technical skill type of issue than it is
the actual you know the utility of
taking this approach
do this this goes back to you know
documentation and buying and you need to
ensure that the team agrees and adheres
to your approach
because if they don't if you've got
developers that start doing their own
thing it can get out of hand and really
tough to maintain quickly
I recommend that you make your your
committing and branching and versioning
tagging all of that stuff is part of
your code review and in retrospective if
you're using a uh if you're in and you
know using scrum or agile or something
like that
because those are going to be the kinds
of things that you want to catch just
like you would want to catch a
misspelling of retro septicus or
whatever that happens to be but if you
make sure that you have everybody you
know check that out that means as in
check that as in review
where is the branch what happened to the
branch how did it get merged where is it
merged did we tag it things like that
those should be part of your code review
then that's going to ensure that the
team feels like they are accountable to
using the process properly
so the bottom line is
it may seem like you're branching and
tagging and merging strategy is just
part of the tool
but if you really want to get the power
of get or any especially distributed
Version Control System like git or
Mercury or some of those other things
out there then utilizing these features
are where you're going to find that
these tools really work for you
and really can save your butt in a pinch
if some you know some issue comes up
some bug comes up or also just to avoid
bugs reappearing and code getting lost
because people just don't follow the
processes
all that being said it is more than
worth it to invest a little time make
sure that you have a good strategy and
that you communicate it and everybody
buys in
hope this helps you out thank you a lot
for your time hello this is Rob with
developmentor also known as building
better developers wanted to announce
that we have
school.developmentor.com feel free to
check it out if you like any of this
information any of the content that
we've sent and you would like to see
more you can come out you can enroll for
free we have free courses we've got
places for you to get better at just
learning a technology our how to's you
can work on your business skills we can
help you with becoming a better
developer as encoding and things like
that a lot of the stuff you've seen on
YouTube we also have out at
school.develop anywhere we just have it
a little more of a educational format
and a way for you to track your progress
as you move forward becoming a better
developer
thank you
Transcript Segments
10.7

thank you

18.89

[Music]

27.48

we are going to talk about in this

30.779

lesson something is very common it's

33.36

called git git and it is for Version

36

Control and

38.04

the key to good version control though

40.079

is that you have a version and branching

42.78

strategy if all you're doing is using

46.2

Version Control to effectively save

48.48

backups of your your files of your

51

source code that's not a bad thing it's

53.34

good to have those it's good to be able

55.079

to return to a point in time however

59.46

once you have anything beyond one

61.98

developer working on your code

64.199

then things like and once you deploy

67.74

your code it's very valuable to have a

70.38

way to get to that version that you

74.52

deployed

75.72

because usually things will carry on and

78

you'll do maintenance and things like

79.619

that and then also how do I branch which

82.5

is even more important because if you've

84.78

got more than one developer how do you

87.119

which is basically what branching solves

88.979

how do you have multiple developers

90.9

working in different areas of the

92.46

application and not have them step on

94.74

each other's toes while they're doing

96.659

the coding

97.86

that is where your branching strategy is

100.5

going to come in

103.439

now with your versioning and your

106.5

branching the key is to be intentional

110.34

this is something that again you know if

112.74

it's just one developer in their own

114.24

little repository it doesn't matter but

116.22

once you get to three 10 developers more

120.72

it is crucial that you have a strategy

124.82

and that is documented so that people

128.34

can know what that strategy is and

131.039

actually you also need to have buy-in

132.84

from your developers however that is it

135.36

doesn't mean they have to be part of the

137.22

design of it but when you push that

140.7

forward when you document it and say

142.68

this is our programming standard This Is

145.44

How We Do Version Control there should

149.04

be something that is a you know holding

152.16

keep people accountable so that they do

154.26

that so that they follow those processes

158.34

now the goal with our versioning and our

161.7

branching really is to easily merge and

165.36

reproduce a path of changes so those are

168

two things we want to be able to easily

169.26

merge changes

170.879

but we also want to be able to if we

174.12

need to go back and reproduce how did we

177.599

get to a certain point in time of of a

181.8

release or a you know a maybe not a

184.2

released version but maybe a tag or a

186.48

label or something like that that is a a

189.66

milestone of some sort

192.48

and now we I mentioned just now we you

195.3

have tags also that are available what

198.18

you can do is you can use a tag to

201

essentially be like a bookmark for a

203.28

place in time or a milestone or key

205.5

features it is not uncommon for tagging

208.44

strategy to be part of branching

210.48

inversioning so when you create a

213.42

version

214.319

instead of it being some

216.84

you know uuid or not very human friendly

219.84

name it has a tag that's something like

222.12

you know version 1.0 beta what version

225.54

1.0 Beta release to something like that

228.9

so that when somebody's looking at the

230.7

tags they can fairly quickly map that

233.879

back to whatever that release is or

237.12

Milestone was that they wanted

239.58

a good example would be spreads

242.22

you may if you're using agile approach

244.92

and you're essentially deploying or

247.86

close enough to it deploying at each

250.5

Sprint then maybe each tag is going to

252.84

be you know Sprint one Sprint two Sprint

254.76

three and it may be more you know have a

257.639

little more information to it for that

258.84

but you may not need it sometimes people

261.419

are going to use dates things like that

263.1

but some way to point back and say if

266.52

I'm looking at all of the code changes

268.8

and commits where do I go to reproduce

272.22

this thing that we had at this time

276.419

now

277.82

branching typically

280.74

is going to be based on some sort of a

283.979

release

285.3

and really and and people can change

288

this up but it's by that I mean is by

290.52

release a stable version of code

293.82

so when you've got you know version 1.0

298.38

so you've got code that works that means

300.96

that it's you're comfortable with it

302.639

it's gone through its tests it's been

305.28

you know blessed by QA or whoever it is

309.479

so you know you have at that point

311.94

something that quote works

314

that is a great basis for a branch

317.16

because then what happens is you've got

319.8

these branches that are based on usually

322.039

adding functionality so you have release

324.36

1.0 and let's say you have a branch that

326.699

is adding security and you have another

329.1

branch that is adding back-end

330.9

integration

332.46

those two things are separate enough

335.1

but they need to have that stable

338.16

Foundation to work with

340.44

and now you're going to come back later

342.5

once the work is done on those and merge

346.199

those things back in

348.36

typically what's going to happen is you

349.979

will branch and then you will mer and if

353.039

you think of it from a like a tree

354.9

branch

356.16

is that you've got your main I say trunk

359.22

and you have a branch that comes off of

360.84

that

362.1

and then you have another branch that

363.479

comes off of that and we'll call that

364.979

Branch two and then you have another

366.479

branch that comes off a branch two

367.8

that's Branch three but when you merge

369.78

what you want to do is you want to

370.979

basically push the code from Branch

373.44

three all the way out on that little

374.82

thing into Branch two and then into

377.28

Branch one and then back into the trunk

379.02

so that you basically merge your way

381.539

back into where the branches came from

385.44

it's sort of like how do you find your

387.24

way back home if you go out and you know

390.36

you start going in a direction and you

392.1

turn left and then you turn right and

393.36

you turn left to right or whatever you

394.68

every time you make a decision

397.919

then in order to get back you have to

400.62

come back to those decision points to

402.36

walk your way back to your home

404.88

may seem a little bit confusing but

407.94

basically what you do is you branch

410.34

and you say okay I'm on a stable

413.4

section of code I'm branching off of

415.56

that I'm going to do stuff based on that

417.6

stable section and then I'm going to

419.46

come back when I'm done and I'm going to

421.86

merge back into that stable because it

423.6

should be if I do it right my stable

426

changes with that stable Foundation

428.3

equals stable foundation with the new

431.52

feature now

433.56

that can be a challenge because if I'm

435.419

working on something that's stable for

438

me and another developer is working on

440.4

something and it's stable for them but

442.44

our things have some sort of conflict

445.199

then when we merge there's going to be a

447.18

conflict with the merge but that's okay

448.86

in a sense I mean yes it's going to

450.84

require work but what it does is it

452.88

means that we know where the conflicts

455.94

are we know that we both had this

457.919

Foundation that worked and so we can

460.56

actually track our changes and figure

462.3

out where do we make our changes

464.16

and then really if we need to can almost

466.919

line by line walk through those to

468.84

figure out how to merge those things

470.819

back and then once you merge and you

473.16

have those things now back into a solid

477.18

working Foundation Branch or actually

480.36

not even Brent like trunk or Maine

482.88

you know Main Branch if you want to call

484.5

it that or release branch

487.62

then you can tag it

490.02

and now I talk about release branches is

491.88

sometimes what happens is you have

493.319

something that would be production

495.66

and then off of that you're going to

496.979

Branch you say okay we're going to go do

498.24

some development well

500.58

at some point that development

502.74

maybe that's going to have a branch and

504.599

you're going to or a tag or something

505.979

along those lines where it's like okay

507.12

we're going to release this to QA but

509.699

then we're going to specifically be

511.02

changing those things in the QA Branch

512.94

as opposed to our development branch and

514.979

we'll eventually merge those and then we

516.899

want to merge to production we'll have

518.52

to merge our way back down to production

521.219

so it's

522.779

it's not the easiest thing to see

524.88

sometimes but if you just think about it

526.44

as the branches are going to get bigger

527.88

and bigger and wider and wider and

529.26

there'll be more branches but as you

530.88

merge then you're coming you're

532.68

essentially in a way traveling back down

534.66

those branches to get yourself down to

536.66

that single master or trunk

542.58

now branching I've talked about a couple

544.5

different ways to do it but I want to

546.06

talk about the one way that I found that

548.279

is very common is it is a branch per

550.44

ticket or per bug so if there's a

553.44

feature if there's a bug that needs to

555.42

be fixed and you create a branch

557.58

you know what the branch is the

559.2

developer working on it does or changes

560.88

and then they merge it back so you what

562.68

you do and this is for your Pros is that

565.26

when you do when you handle this

567.06

approach the changes tend to be small

570

there's not a lot of changes usually

571.98

that are made which means that when you

573.779

merge it back merging is going to be

575.459

more likely to be successful and less of

578.94

a headache

580.68

now once you do that it's the con is it

583.68

now every time you're get a bug or a

587.82

ticket or task you've got to split off

590.1

you've got to create your branch you've

591.3

got to make sure the developers you know

592.86

knows what branch they're on and then

594.779

there's got to be a merge back and then

596.88

eventually merge that back and you can

598.44

end up having a lot of branches but you

600.66

can merge and prune so you can go to a

602.82

point where you say hey once we get to

604.68

this point once we get to this bug being

607.2

fixed when we're going to merge it back

609.86

we know we're not going to need that

612.18

Branch anymore so we're going to merge

614.04

back and then that Branch just appears

615.839

and so in this case you maybe have a lot

618.18

of branches but they end up disappearing

619.86

because you're cleaning them up as you

621.72

go

622.74

and now it's the same thing

624.959

you may want to do that and have

626.279

branches so that you can go into you

628.38

know version 2.0 or 3.0 so that you

631.32

would go you know release version 2.0

634.5

but if there were bugs to be fixed that

636.899

were in 1.0 you could always work off of

638.82

that branch and then have a you know 1.1

642.12

release even after 2.0 was even released

645.48

maybe even way after it was released

648.48

but if you do this per ticket bug it

651.06

tends to keep it pretty

653.16

essentially pretty close to the branch

655.8

that you're working on you know saying

657.18

assuming it's like a you know a version

658.56

Branch or development versus maybe

661.56

staging or production the nice thing

664.019

about this is it's it's very it's gonna

666.42

be very focused and so it's easy to just

668.7

you know pop out do a branch make your

670.56

fix

671.7

test it specifically a lot of times

674.459

because and then the merge you can test

676.2

very specifically because you're not

678.66

having to you didn't touch a lot of

680.64

stuff

681.54

the tests that you used on the on the

684.06

merging or you know as you branched and

686.459

fixed it

687.899

those tests should be effectively be

690.48

able to be added to your overall testing

692.82

strategy verify it and move on

696.12

so there's some there's quite a few Pros

698.16

to taking this approach the cons are

700.8

really usually more about people just

702.779

not being as comfortable creating

704.339

branches and merging and things like

706.38

that and it's it's really more of a

709.019

technical skill type of issue than it is

711.86

the actual you know the utility of

716.04

taking this approach

720

do this this goes back to you know

722.399

documentation and buying and you need to

724.86

ensure that the team agrees and adheres

726.72

to your approach

728.22

because if they don't if you've got

729.839

developers that start doing their own

731.1

thing it can get out of hand and really

733.98

tough to maintain quickly

736.62

I recommend that you make your your

739.98

committing and branching and versioning

742.7

tagging all of that stuff is part of

745.079

your code review and in retrospective if

747.24

you're using a uh if you're in and you

750.72

know using scrum or agile or something

753

like that

754.8

because those are going to be the kinds

758.22

of things that you want to catch just

760.019

like you would want to catch a

761.579

misspelling of retro septicus or

764.04

whatever that happens to be but if you

766.5

make sure that you have everybody you

768.36

know check that out that means as in

770.279

check that as in review

772.56

where is the branch what happened to the

775.079

branch how did it get merged where is it

776.7

merged did we tag it things like that

778.44

those should be part of your code review

780.18

then that's going to ensure that the

781.8

team feels like they are accountable to

784.139

using the process properly

786.24

so the bottom line is

788.94

it may seem like you're branching and

791.88

tagging and merging strategy is just

794.94

part of the tool

796.98

but if you really want to get the power

799.2

of get or any especially distributed

801.779

Version Control System like git or

804.06

Mercury or some of those other things

805.2

out there then utilizing these features

808.5

are where you're going to find that

811.2

these tools really work for you

813.3

and really can save your butt in a pinch

816.66

if some you know some issue comes up

819.12

some bug comes up or also just to avoid

822.5

bugs reappearing and code getting lost

825.959

because people just don't follow the

827.94

processes

829.5

all that being said it is more than

831.66

worth it to invest a little time make

834

sure that you have a good strategy and

835.74

that you communicate it and everybody

837.36

buys in

839.1

hope this helps you out thank you a lot

841.44

for your time hello this is Rob with

843.839

developmentor also known as building

845.519

better developers wanted to announce

847.92

that we have

849.079

school.developmentor.com feel free to

851.339

check it out if you like any of this

853.5

information any of the content that

855.48

we've sent and you would like to see

856.68

more you can come out you can enroll for

858.779

free we have free courses we've got

861.06

places for you to get better at just

863.579

learning a technology our how to's you

866.339

can work on your business skills we can

868.44

help you with becoming a better

869.88

developer as encoding and things like

872.279

that a lot of the stuff you've seen on

873.959

YouTube we also have out at

876.12

school.develop anywhere we just have it

878.22

a little more of a educational format

880.68

and a way for you to track your progress

882.72

as you move forward becoming a better

885.54

developer

896.12

thank you