GIT: Working with Branches

Sharing buttons:

hey guys how's it going today I'm really

sorry you guys about git branching not

the kind of branch that makes this table

here but get branching like something

you'll be able to use in your workflow

alright so why do we have branching well

if you work in with you source code a

lot lots of files and lots of folders

that's what it is then you'll know that

you know like because there's so many

files and so many things can go wrong

you don't really want to have to keep

track of like what's changed and what's

not changed and perhaps you have one

copy of your source code actually

everything is working and you don't want

to mess with that

right so you're kind of like afraid to

make changes to it just for the fact

that you know you you know that

everything is working and you don't want

it to go bad right so what you would

normally do is you would make a copy of

like a duplicate of what is already

working and then you would just work on

the duplicate that you made and you know

now okay I've got the working copy so in

a way just fine now I can make man

whatever changes I want

well git has a very efficient way of

dealing with that it's called branching

let's start by taking a look at creating

our first branch alright so here we are

so let's recap from the previous episode

I've got my branch open over here it's

the master branch and in the master

branch we have two lines of code over

here is my first line and no one ever

reads the readme and what I'm going to

do here is I'm going to create the

develop branch right so the master

branch is that we're just going to leave

that alone and what we're going to do is

want to create a master by develop

branch git branch develop all right so

let's check if we have that branch or

not git branch so we have the branch now

and what we can do is we can switch over

to working on the actual you know the

actual develop branch so get checkout

develop alright so now we're on the

develop branch let's make some changes

to our file we are on the develop branch

it's status so I'm going to do a commit

git commit am so this time I'm just

going to use the - am this is kind of

like allows us to not have to do git add

so we just do git commit a and then M so

everything happens in one command all

right so we are adding something new

great so now if I check out git log

I'll see that I have three commits now

if I go back to my master branch get

check out master you will see that we're

back to the snapshot that we made

earlier right so this is this is what

I'm talking about in terms of snapshots

so we don't have to worry about what's

on the master branch we know that that

works and that's deployed so we just

worry about what we want to build which

is a develop branch so get whoops so I'm

going to switch back here get check out

develop ok so what else can we do we can

create another branch and generally this

is kind of like leading into the kind of

workflow that I want to show you guys so

what I'm going to do here is I'm going

to create a branch called a feature

branch so get check out - B feature new

feature so this is a new way of creating

a branch you can do git checkout - B and

if the branch does not exist it will

automatically create it for you great so

if I now go over or open this up in the

text editor so we're already on the

feature branch as you can see down here

if I head over to the file will see that

the develop branch changes we made in

the develop branch still exists over

here that's great so whenever we're on a

branch and we create a new branch it'll

create a branch reference off of the

brands that we were on I hope that

doesn't confuse you all right so let's

let's let me recap that Eleuthera so I'm

going to get check out into the develop

branch over here so when I was on the

developer and I type in the command git

checkout - B feature new feature branch

what this is going to do is going to

reference off the develop branch and

create a new branch based on the develop

branch if I was on the master branch it


friends off the master branch instead

alright so here we are so we can go

ahead and so we can check out feature

new feature and then here all we have to

do is just add a new feature so wow that

was easy

okay so now we have a new feature added

right what we can do is get commit done

with new feature get checkout develop so

as you can see the developer and still

just has three lines of code whereas the

feature branch has now four lines of

code now with all these creating all

these branches why am i showing you all

this stuff well if you think about it

you know when you're working with a

piece of source code you're working with

multiple people in your team and it it's

really cool to be able to create a

branch and assign that branch off to

someone so for example you have multiple

feature branch and you know that okay

you have five developers on your team

and what you can do is like say okay

developer a go ahead and work on this

branch developer B go ahead and work on

this branch and then basically what you

know what you do is you have each person

responsible for that branch and they

will go ahead and build the app whatever

they're responsible for in that branch

so it's all isolated so the change is

made by one person is not going to be

conflicted and mess up the changes made

by the other person because the other

person knows that he's got the working

copy which is from the develop branch

and then he's building off he or she's

building off of that alright guys so

this is going to wrap it up for the

episode called branching in the next

episode we're going to be taking a look

at how we can merge all those branches

together and it'll slowly lead onto kind

of the kind of workflow that we use in

our company at Khoda me so I hope you

guys found that useful don't forget to

Like and subscribe to our Channel and

don't forget to share this video with

your friends and family and also we have

a rails foundation course coming up and

if you're interested in taking a look at

that don't forget to head over to our

Gumroad website and subscribe and put in

your email over there so once we're done

recording the videos for that course we

can notify you and let you know about it

alright guys that's

pop it up see you guys in the next one