in the last video we set up our github repo and cloned it locally now what we're going to
focus on is creating our own branch adding some changes committing them and then pushing them
up to our repo on github here we are in visual studio code this is the editor i'm choosing but
obviously you could certainly choose whatever you want the reason i really like using visual studio
especially with git is the fact that there is a built-in terminal what we can do here is right
click and open integrated terminal now there are a ton of different commands with git obviously you
could just write get here and it's going to give you all these commands with different descriptions
about it for example what we've done so far is git clone and what we'll focus on here is git add
which is going to add file contents to the index and the index being your local branch your local
version of things and we'll look at git commit which is going to record the changes we'll look
at get branch we're going to create a branch and then finally git push which is to push the changes
from our local branch up to github where it will store those changes as a branch there as well
and clear this so first thing i'm going to do is get branch and we can see here it
just pulled our main branch which is that core foundational piece that we're building off of
and that's it there's nothing else we haven't created anything new in order to create a new
branch which is if you think of it as a tree you know that's the analogy here
this is the main trunk of the tree the main version of everything and we want to create
a branch that we can work on the side but not actually impact these main files
or folders themselves so now to create our own branch what we can type is git branch and then
dash c for create and then the name of the branch so in our case we'll do my new branch we're using
the git command saying branch using the c flag for create and then giving it a name my new branch
now if we do git branch again it'll show the list of them and we can see main is still
there and green and this asterisk indicates that that's what we're on and then my new branch is
also there but that's not what we're currently on checkout moves you to that branch so we can do git
check out my new branch and we can see now we're switched to my new branch and if we do get branch
again we can see that's where we are because we didn't make any changes these are exactly the same
now one thing i'll point out here is if you're any of this is confusing or you want some more
documentation you can always do something like this get branch dash dash help it's going to open
up a help file from git that you originally downloaded it comes with it so you can see
everything about it learn what all the commands are how to use them so that's really helpful
and now let's try to actually make some changes and add a file to this new branch
in this case we'll just create a very simple
uh hello world python file we'll do new file call this hello world.py and we'll just print
hello world and that's it now if you're in visual studio code you'll see over here this connects
to github now you have to you can set this up to connect to github and it will track your changes
here so you can actually see it here as well but we won't focus too much on that now in this
situation this change is only made on this branch this new file exists on this branch but not here
git status we can see the branch is up to date with the origin which is what it was
originally branched off of it's up to date with that and we can see that it has this hello world
file but it has not been committed nothing added to commit but untracked files are present so
now if we want to actually add this file to our branch the way we can do that is git add
and you can say the name of the file so we can go hello world dot py and this would do it so if
we do this now if we do get status new file it's green it's been added to the branch the other way
you could have done that but let's say you made a change to 50 files or 10 or you know whatever
you could do git add and then just the dot that would add all of your untracked files here rather
than just one but in our case we're just doing the one now the next step is it needs to be committed
so you can think of add as it's kind of in this holding pattern right before you commit it
once you commit like it sounds it's essentially finalized at that point so we'll do git commit and
it's going to take everything that you have here that's staged and ready to be committed and add it
to your branch but for every commit you should add a note some sort of message indicating what's
actually happening within that commit so what are these changes these files what do they represent
to do that we'll do dash m for message
and say adding hello world file oops i forgot quotations so we can do
quotations around it and now we can see new branch added hello world file there's a specific hash
involved with that change with that commit and now it's no longer just a stage change it's committed
to the branch it's there so again we have these two branches at this point we've committed a new
change to my new branch but that doesn't exist on main so let's see here we see hello world if we
check out main hello world goes away because maine doesn't have that if we get check out
my new branch we're back here it says you're ahead of origin main origin main meaning this
was branched off of that main branch and it's ahead by one commit which is what we just did
right now this is only locals if we look at github here and refresh we go to branches all we
have is main right now github is unaware of this branch that we have here it's only local to you
and if multiple developers were using it and had their own branches until they push their
changes that they're doing to github github has no way of knowing about it so that's what we'll
do here now so let's go ahead and do a git push now what this is saying is in order to push it
up you actually need a remote upstream branch we'll cover this more in depth on a different
video but essentially what we want to do in this case and most of the time is git push
origin head and we can set this by default if we do the config but we won't for now
again let's cover this in a separate video but to get us going here we're going to do git
push origin head now it will understand where it wants to go and now we can see my new branch is
recognized on github here it is we can jump into it we can see here are the different files here's
that new file which if we were to go to just our main you know main version here it doesn't
exist now we have the ability to switch branches just to see what the files look like again some
of these are going to have hundreds of branches potentially you can switch between them pull them
down do what you need to do so now it's available here and we can do what's called a pull request
to have people review it and stuff like that which we'll cover in a separate video
but that'll do it for this video at this point we've now created our own branch
we've made some changes to that branch and pushed that new branch
along with its changes to github for us to now review and hopefully get some approvals
so that it can get merged into our main branch for everybody else to see and begin to work with you