434 lines
37 KiB
Plaintext
434 lines
37 KiB
Plaintext
|
|
Episode: 2516
|
||
|
|
Title: HPR2516: Intro to git branch
|
||
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2516/hpr2516.mp3
|
||
|
|
Transcribed: 2025-10-19 04:34:03
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
This in HPR episode 2,516 entitled Intro to Get Branch.
|
||
|
|
It is hosted by Klaatu and in about 44 minutes long and Karina Cleanflag.
|
||
|
|
The summary is Intro to Get Branch.
|
||
|
|
This episode of HPR is brought to you by AnanasToast.com.
|
||
|
|
Get 15% discount on all shared hosting with the offer code HPR15.
|
||
|
|
That's HPR15.
|
||
|
|
Better web hosting that's honest and fair at AnanasToast.com.
|
||
|
|
Intro to Get Branch
|
||
|
|
Hi everyone, this is Klaatu and you're listening to Aatrox Radio.
|
||
|
|
This is the third episode in my Intro to Get series.
|
||
|
|
Today we're going to talk about Get Branch.
|
||
|
|
Get Branch's are really important, they're kind of the killer feature of Get, I guess,
|
||
|
|
or at least they're very important to get functionality.
|
||
|
|
So in order for Get to really work well, you want to be able to take work that is
|
||
|
|
getting done and make it a little bit modular.
|
||
|
|
That's what branching lets you do.
|
||
|
|
You can start work on something, put it into a branch, and no one will know that you're
|
||
|
|
doing that thing.
|
||
|
|
Not for secrecy purposes, just because that way when they go in to add some feature or
|
||
|
|
fix some bug, they're not accidentally trampling all over the file that you are working on
|
||
|
|
right now.
|
||
|
|
But what happens when someone works on a file and you are working on a file, you both
|
||
|
|
have branches and then you both try to commit those changes to the same location.
|
||
|
|
Well that's something that Get can handle and we will cover that in this episode.
|
||
|
|
So let's get started.
|
||
|
|
So last episode we set up kind of a local workspace consisting of a directory called Alice,
|
||
|
|
a directory called Bob, and a directory called Fake Remote.
|
||
|
|
Alice and Bob are developers, Fake Remote is the server that exists somewhere out there
|
||
|
|
in the world.
|
||
|
|
So right now both Alice and Bob are working on Master, on the Master Branch, that's kind
|
||
|
|
of bad practice.
|
||
|
|
It's considered once you start working with lots of people or once you start making lots
|
||
|
|
of changes really, you don't really want to work on your Master Branch because I mean
|
||
|
|
in a way you're kind of, well you're no longer leveraging the modularity that Get
|
||
|
|
Branches affords you, so you don't really want to do that.
|
||
|
|
So it's very, very common to make a new branch when you start working on something and that
|
||
|
|
way you can work on this branch, you can save all your changes and later once you feel
|
||
|
|
comfortable with what you've got, you or the project lead can then merge this branch
|
||
|
|
into the Master Branch and it becomes kind of part of the official distribution or the
|
||
|
|
official release I should say.
|
||
|
|
So let's first, let's look at making branches.
|
||
|
|
So let's go into Alice's directory because that's the way we've been going.
|
||
|
|
So if we do a Get Branch, get Space Branch, it returns to us all the branches that
|
||
|
|
exist and you remember that we did that once before in the previous episode, actually
|
||
|
|
we did Get Branch and we did a secret Get Branch command called Get Branch Dash Dash
|
||
|
|
All or if you're into short commands, Dash A. Get Branch Dash A shows you your Master Branch
|
||
|
|
that is located on this computer, on this physical box and then there's also, it turns out
|
||
|
|
a remote slash origin slash Master which as we learned in the previous episode is a branch
|
||
|
|
that exists over on the server, on the fake remote server.
|
||
|
|
So that exists, that's just something important to keep in mind.
|
||
|
|
So if we do the Get Branch Master is shown, now we can create a new branch and simultaneously
|
||
|
|
switch to that branch in all in one command and that's how everyone does it.
|
||
|
|
There is a way to do it separately, kind of like I don't use Get Pull, I use Get Fetch
|
||
|
|
and get Merge in these episodes.
|
||
|
|
I'm not going to do it separately for this one, get the composite command just, it honestly
|
||
|
|
just makes more sense.
|
||
|
|
So the way to do this is the way that everyone does this is get checkout Dash B for Branch
|
||
|
|
and then the name of the branch that you want to create and change to.
|
||
|
|
So we're going to call this one Alice underscore dev, it says switched to a new branch Alice
|
||
|
|
underscore dev and if I do a Get Branch I see that yep, the Alice underscore dev has a
|
||
|
|
little asterisk by it so it's the active branch, I don't know if you can hear that but there
|
||
|
|
is construction happening outside my apartment so apologies and then there's the Master Branch
|
||
|
|
which is all alone down at the bottom kind of being ignored and not highlighted.
|
||
|
|
That's good.
|
||
|
|
I do a cat of, well if I do an LS I see that I still, nothing's really changed, I've
|
||
|
|
got zero one dot TXT and if I cat zero one dot TXT it's Hello World dot blank line, welcome
|
||
|
|
to Get dot and that's the file that's just as I left it on Master as far as I can recall
|
||
|
|
so not that exciting but what is cool is that we can, we can now change things, we can
|
||
|
|
do weird things with this branch.
|
||
|
|
So we can do Emax zero one dot TXT and I will rewrite this, I'll say Hello World with
|
||
|
|
an exclamation mark and then instead of a blank line I'll put some dashes to make it
|
||
|
|
look like an underline and then I'll put a blank line on line three, pushing welcome
|
||
|
|
to Get down to line four and then I will add some, welcome to Get version control there.
|
||
|
|
So we've got a couple of changes there in this branch.
|
||
|
|
So I can now get add dot or get add zero one dot TXT whichever I prefer and then get commit
|
||
|
|
dash M for message and I can say made the file prettier.
|
||
|
|
So I think I'm good to push.
|
||
|
|
Now pushing a new branch to a remote server is a little bit of a tricky thing which is
|
||
|
|
weird because I mean it's pretty common but there are lots of different ways that you
|
||
|
|
might want to manage your branches rather than going into all the different use cases
|
||
|
|
for managing branches because I think you'll possibly, I think when you hit upon them
|
||
|
|
in real life you will understand, it will just come naturally to you in other words.
|
||
|
|
If you if you're managing something and you realize I don't need that branch to be on
|
||
|
|
the remote like I don't need to track this on the remote then you'll know when that happens.
|
||
|
|
So what you can do then is get push and then dash U. Dash U stands for any variety of changing
|
||
|
|
option.
|
||
|
|
It used to be dash dash set dash upstream and now I think it's dash dash set dash upstream
|
||
|
|
dash two or something like that either way you can just use get push dash U for set upstream
|
||
|
|
or something like that it depends on the version of get you're using.
|
||
|
|
Get push dash U origin because we're pushing things to the origin and then of course what
|
||
|
|
are we pushing while we're pushing head capital H EAD capital H capital E capital E capital
|
||
|
|
E and then hit return and it tells you the branch Alice dev set up to track remote branch
|
||
|
|
Alice dev from origin and everything is up to date now.
|
||
|
|
So what happened there is that we pushed the branch and we have linked this branch on
|
||
|
|
my local box this Alice underscore dev.
|
||
|
|
We have linked it to the one that we just pushed it to push to the remote server.
|
||
|
|
You can push it without doing that and it will behave differently.
|
||
|
|
But I think more often than not in real life most use cases you're going to find that
|
||
|
|
what you really want to do is get push dash U origin head.
|
||
|
|
You only have to do the dash U the first time you push because from now on it is set
|
||
|
|
to track the remote branch.
|
||
|
|
Now you can if you want you can just keep doing dash U it wouldn't doubt add the dash U
|
||
|
|
on your push but you don't have to you only have to do that really technically the first
|
||
|
|
time that you push that that branch because the remote server doesn't know that the branch
|
||
|
|
dev exists all it's aware of right now is master so we've just pushed a new one to the
|
||
|
|
remote so we need to tell it hey this branch is also here on this local machine so when
|
||
|
|
I do a get pool from now on you you pull from dev as well that's why we do that.
|
||
|
|
Okay so now if we CD over into Bob's directory and we do a get let's do a get well let's
|
||
|
|
do a get branch first and we see that we are we're we just have master here no there's
|
||
|
|
nothing nothing of interest here so let's do a get branch dash dash all if you'll recall
|
||
|
|
from the previous episode that was a way to look at branches that include both the local
|
||
|
|
branches on on our local machine and the ones over on the remote server so get branch
|
||
|
|
dash dash all shows from me master remotes origin head and remotes origin master and and
|
||
|
|
remotes origin head points to origin master so that's that's kind of what we would have
|
||
|
|
expected really so now let's do a get fetch and it looks like it has found new information
|
||
|
|
on the server and it tells us a new branch exists called Alice underscore dev and that
|
||
|
|
is on origin slash or Alice underscore dev and we can do a get branch dash dash all or
|
||
|
|
dash a if you like short commands short options and and now we indeed have a new branch available
|
||
|
|
so there's master there's remotes origin head there's remotes origin Alice underscore dev and
|
||
|
|
there's remotes on remotes origin master so so Alice's branch is appearing sort of in our
|
||
|
|
table of contents but it's not something that Bob created it's not something that Bob really
|
||
|
|
probably has been invited to muck around in and so it's just kind of hanging out there off
|
||
|
|
off in the distance it's existing it's on the server we we can see that it's there but there's
|
||
|
|
not a good reason for us to have it in our active sort of default get branch listing so Bob
|
||
|
|
could create his own branch you call it Bob Dev and he could he could do things on Bob Dev
|
||
|
|
and in fact I guess let's go ahead and do that now so if you'll recall it's a get checkout dash
|
||
|
|
B for Bob underscore dev and he will go into oh did we switch to it let's do a get branch to make
|
||
|
|
sure yes we're now on Bob Dev and so now let's go into emax01.txt so the version that Bob has
|
||
|
|
on his computer is the old version hello world period blank line welcome to get period so that's
|
||
|
|
the old version now you'll recall that Alice just modified this so what we're going to do is we're
|
||
|
|
going to change it drastically so let's say that Bob Bob kind of was thinking the same thing he's
|
||
|
|
like well we need to we need to make this a little bit more formal so he goes in and and starts
|
||
|
|
doing some stuff and he and he defaults to maybe mark down so he he does a hash symbol and he puts
|
||
|
|
will put an introduction that's what we'll call it hash introduction the first line of which is
|
||
|
|
hello world and we'll keep that as is but that's now been pushed down to line three line four is
|
||
|
|
now blank and it says welcome to get and then he's going to do he's going to be clever and he's
|
||
|
|
going to do a man get and he sees that get calls itself the stupid content tracker that's
|
||
|
|
right out of the man page so he's going to grab that and paste it in there welcome to get comma
|
||
|
|
the stupid content tracker I don't think it's stupid but I guess the devs do so there we go
|
||
|
|
you've got six lines Bob is a little bit verbose and and that's his version of it so now we're
|
||
|
|
going to do a get add dot we'll do a get status just to make sure that we know what we're working
|
||
|
|
with yeah changes to be committed is zero one dot txt so he will do a get commit and for his
|
||
|
|
commit message he'll say that you know Bob added some mark down very little mark down but that's
|
||
|
|
what he did and then we'll do a get push dash you origin head so now we've got we've got two
|
||
|
|
branches Alice dev and Bob dev each one of those exist on the individual developers machines
|
||
|
|
and they're different they're the same file they made different changes to the same file so
|
||
|
|
I'm going to switch back over to Alice and let's assume that Alice maybe is in charge of this
|
||
|
|
project because she was the first one in so let's say that she's she's pretty comfortable with
|
||
|
|
her changes lately she's feeling pretty good about it so she decides that she's going to merge
|
||
|
|
her changes from Alice dev into the master branch so to do that she would do a get checkout of master
|
||
|
|
and then if she's a she's a good get user she would instinctively do a get pull
|
||
|
|
and she does now when she does a get pull she might she would have the reason she'd have been
|
||
|
|
doing that the get pull or the get fetch whatever it is because she she wants she wants to make sure
|
||
|
|
that master is up to date on her local machine now she's the project lead she probably feels
|
||
|
|
pretty comfortable that it is but maybe she has several computers she's not sure which one
|
||
|
|
she was at last or she thinks okay well I'm going to go ahead and do a get pull to make sure that
|
||
|
|
this is all as as up to date as possible now when she did that because because get is not stupid
|
||
|
|
get fetches things like Bob dev which she didn't how Alice didn't know Bob dev existed but but
|
||
|
|
there it is Bob dev the branch I mean she knows she knows that Bob exists because she's given Bob
|
||
|
|
permission to muck around on the on the fake remote server but but she didn't know that he had
|
||
|
|
created recently a new branch called Bob underscore dev so now if she's if she's very clever
|
||
|
|
or not so clever because there are only there's only one file in the whole repository so she might
|
||
|
|
want to look at what what is in what what what's going on here in the Bob dev branch she could do that
|
||
|
|
and the way that she would do that is she would do first get branch dash a to list all of the
|
||
|
|
branches and she would see that there is a Bob dev now well if she wants to if she wants to sort of
|
||
|
|
I think of it as activating a branch because on her machine she's got master and she's got Alice
|
||
|
|
dev so she wants to look into Bob dev she needs to pull that down off the server by default get
|
||
|
|
does not give her Bob dev because Bob dev belongs to Bob so why does she need a copy of that she
|
||
|
|
probably doesn't I mean that's why branches exist so that you don't have to go in and muck around
|
||
|
|
in each other's workspace so she would probably you know if she wants to do this and and it's
|
||
|
|
reasonable under in these circumstances that she might want to do that so and besides she's
|
||
|
|
the project lead so she has every right to do that so I mean Bob should would Bob would expect
|
||
|
|
and and and and it would be fine I would I would hope I mean what kind of project would it be if
|
||
|
|
you didn't trust other people to you know if you if you didn't want your work to be looked at by
|
||
|
|
others that would be weird so so it's not like an invasion of privacy is what I'm trying to tell
|
||
|
|
you it's just you can look at the other files it's just by default get doesn't clutter up your
|
||
|
|
workspace with other people's work in progress so we're going to do a get checkout of Bob underscore
|
||
|
|
actually origin slash Bob underscore dev now the result looks a little bit scary get warns you
|
||
|
|
that you are now in a detached head state you can look around make experimental changes and commit
|
||
|
|
them and you can discard any commits you make in this state without impacting any branches by
|
||
|
|
performing another checkout if you want to create a new branch to retain commits that you create
|
||
|
|
you may do so now or later by using the dash B with the checkout command again example get checkout
|
||
|
|
dash B Bob underscore dev so in other words right now because Bob dev that layer that we've fetched
|
||
|
|
is if you'll recall I think last time I was using gimp layers as an example it's kind of a
|
||
|
|
floating layer right now it's not it hasn't been locked down and anchored to anything so by checking
|
||
|
|
it out you can look at it but you're not necessarily you know you haven't really brought it down
|
||
|
|
to your local workspace and and and you can look at this I mean so we're so we're in this weird
|
||
|
|
detached heads head state so in terms of the tape recorder the the playhead is is above the the
|
||
|
|
tape it is not playing anything it's just kind of hovering over there so if we do a cat zero one
|
||
|
|
dot txt we see Bob's version of that file hash introduction hello world welcome to get the stupid
|
||
|
|
content tracker I don't think it's stupid but I guess the devs do all right so now now Alice knows
|
||
|
|
that Bob has been editing the same file as she has been and that's a good thing to know now a lot
|
||
|
|
of times when there are lots and lots of files and lots and lots of developers working you just don't
|
||
|
|
I'm sorry there's there's construction going on outside my apartment so if you hear like power tools
|
||
|
|
that's that's why so anyway in real life when you have a lot of files and a lot of different devs
|
||
|
|
working on a lot of different files you you don't you're not going to check out every single branch
|
||
|
|
that pops up in your hidden branch dash dash all list and see what's going on and make sure that
|
||
|
|
it's it's everything's clear I mean that would just be ridiculous that's that's silly so
|
||
|
|
Alice would have done that in this specific situation because there's only there's literally only
|
||
|
|
one file in their repository so she might have thought oh gee I wonder what Bob dev is up to
|
||
|
|
because quite possibly he's you know doing the same thing that I'm doing and in this case she
|
||
|
|
would have seen that yeah but let's pretend like it's real life and and she didn't she didn't
|
||
|
|
think oh I should look at Bob's branch that would be great to do she wouldn't actually care
|
||
|
|
so we're gonna check out Alice underscore dev again so we're gonna do get checkout Alice underscore
|
||
|
|
dev we'll just do a cat of zero one again and it's back to her version hello world exclamation
|
||
|
|
point underlying welcome to get version control so she's happy with this so she's going to go over
|
||
|
|
to the master branch get checkout master and cat zero one again okay that's the old version so I
|
||
|
|
think at this point she's ready to merge this into master so she's going to do a get merge
|
||
|
|
and then she's going to put master because she likes to do explicit commands even though she
|
||
|
|
knows that she wouldn't have to do master it'll just default to her current master her current
|
||
|
|
branch but she'll do get merge master space Alice underscore dev and it says it's updating from
|
||
|
|
one e four to two six two fast forwarding zero one dot txt five so three plus three additions and
|
||
|
|
two minuses one file changed three insertions two deletions and now if we do a cat zero one dot txt
|
||
|
|
we see that it is indeed her version her her her her development version of hello world has now
|
||
|
|
been committed to to this uh to this branch to the master branch so now if we do a get log
|
||
|
|
and i'm going to do the dash dash one line trick so that i can see it all on one screen
|
||
|
|
and i'm going to pipe it to t apparently so that i don't get dumped into less uh then we see that
|
||
|
|
yes she's got three law she's got three uh commits three log entries she's got uh two six two which
|
||
|
|
has made the file prettier one e four which is Bob's first commit and then d five two added a text
|
||
|
|
file so there we go that's great some things have happened but now let's just experiment around
|
||
|
|
and see what would happen for instance i i mean we could do this either way we could say that either
|
||
|
|
Mary has decided to merge Bob's version into to master which probably would be the realistic
|
||
|
|
way to do it because someone would have someone has to have the final say and that's usually
|
||
|
|
the project lead so if Alice is project lead and she would probably be the final say as to what
|
||
|
|
actually gets merged into master and what would really happen is that Bob would email her and
|
||
|
|
say hey i've got a new branch it's called Bob underscore dev and i've pushed it to to the remote
|
||
|
|
to fake remote uh it's got some really great changes in there do you can you look at it and see
|
||
|
|
if if it could merge you could merge that into the master branch and he would probably hopefully
|
||
|
|
say it a lot less verbose than that although Bob i think we established this kind of verbose
|
||
|
|
so so that's what would happen in real life now in in the other real life where the cloud is king
|
||
|
|
people push their branches well so they they make a fork of a project which is annoying
|
||
|
|
and then you go in and make your changes and then you go back to the web and you go into the website
|
||
|
|
and you click a little button that says uh pool request or if you're hip it's a PR so you issue you
|
||
|
|
create this PR and then the the project lead the person managing the repo the real repo that you
|
||
|
|
forked uh looks at it and says oh someone wants to merge some stuff and they look at your changes
|
||
|
|
and they they decide if they want to keep it and then they click accept and then and in the
|
||
|
|
background get hub or get lab or whatever you're using does the the get merging of different branches
|
||
|
|
and and that's that's a perfectly acceptable way to do it it's just a little bit annoying for me
|
||
|
|
because that means you have to open up a a web browser and you have to go in and click on the thing
|
||
|
|
and and it's just it i would rather just do this all in and get personally but it's pretty popular
|
||
|
|
these these uh social coding platforms so it's it's really really common to go in and and create a
|
||
|
|
pool request and and as i say in that model you don't actually even bother cloning the repository
|
||
|
|
first you had you you first quote unquote fork the repository which is weird because
|
||
|
|
yes it's a fork but it's not really a fork because you're actually working on something that
|
||
|
|
you're going to push back to the project that's not forking anymore that's the you're you're just
|
||
|
|
you're sort of just you're really just branching but anyway so you fork it you clone your own fork
|
||
|
|
and then you go back to the original and create a pool request so that they can then you know
|
||
|
|
the behind the scenes get something get cloud whatever can create a new remote to your
|
||
|
|
your to your forked repository pull fetch the changes from said repository delete the remote so
|
||
|
|
that now it doesn't exist anymore and present it to the the project owner for emerge great
|
||
|
|
but it's all magic it happens behind the scenes you don't have to worry about it okay so
|
||
|
|
what i'm trying to say i guess is that in real life i think Alice would do this merge
|
||
|
|
so i guess let's just go with that um yeah why not let's do that let's let's let's just do it so
|
||
|
|
what where do you get branch so where she's on master right now so remember to see
|
||
|
|
Bob dev she just did a get check out Bob dev and it said that uh you can do that you can do
|
||
|
|
a Bob dev is we've we've done a get pool so Bob dev exists in in the floating layer and so
|
||
|
|
it just it created and it it has created and switched over to Bob dev because we just did a
|
||
|
|
straight get checkout Bob dev so if we do a get branch we see that we are on Bob dev now
|
||
|
|
and we can do a cat of a one dot txt and there's an introduction in a hello world and welcome
|
||
|
|
to get the stupid content tracker great all right so now we're going to check out master again
|
||
|
|
because we've got Bob dev locally and she's going to try to well she'll do a get pool again
|
||
|
|
just to make sure that nothing has changed it's already up to date okay cool and so now we're
|
||
|
|
going to try to do a get merge into master which is the current branch of Bob dev Bob underscore
|
||
|
|
dev and it says auto merging is zero one dot txt and then it says conflict content merge conflict
|
||
|
|
in zero one dot txt automatic merge failed fix conflicts and then commit the result so that's
|
||
|
|
scary a lot of people get very worried about messages like that and it can be scary I will admit
|
||
|
|
but don't worry it's first of all recoverable and second of all your data is not in danger a lot
|
||
|
|
of people get really freaked out about that and think oh my gosh I'm going to lose all my changes
|
||
|
|
conflicts have happened things have gotten lost no nothing's gotten lost that's the that's one of
|
||
|
|
the strengths of get is that these things can happen and you don't have to worry about them so
|
||
|
|
what we're going to do we're going to go just straight off the bat just emax zero one dot txt why
|
||
|
|
well because it said conflict merging merge conflict in zero one dot txt so we know where the
|
||
|
|
problem is it's in zero one dot txt so here's a here's a sample of an incur of a conflict of
|
||
|
|
a conflicted merge experience and it's kind of easy to see when it's something so basic
|
||
|
|
a lot of times in real life you know it'll be a lot that there's a lot more text and things kind of
|
||
|
|
get lost in the in the shuffle but but there it is so this is actually a pretty a pretty
|
||
|
|
sort of an unexciting conflict to be honest because it's basically you can have this or you
|
||
|
|
can have that because they're the files have have diverged so heavily so we have the first line
|
||
|
|
we have a bunch of chevrons less than less than less than less than less than less than less than
|
||
|
|
less than less than head and then it says hello world exclamation mark dash dash dash welcome to
|
||
|
|
get version control and then a bunch of equal signs so the equal signs is the divider
|
||
|
|
everything above those equal signs as you can possibly guess is head that that's where the
|
||
|
|
that's where the current state of the repository is right now it's head right everything that's
|
||
|
|
been committed is in head and and that is the head of the repository right now hello world dash
|
||
|
|
dash dash welcome to get version control okay and then there's the equal signs and then there's
|
||
|
|
the hash introduction hello world welcome to get the stupid blah blah blah and then a bunch of
|
||
|
|
greater than signs and then Bob Dev so in other words everything from that equal those equal
|
||
|
|
signs down to those chevrons is the stuff that's conflicting from from Bob Dev so how do we resolve
|
||
|
|
this well we have to choose we have to choose which one we want so what we can do is we could say
|
||
|
|
well first of all we can get we can ditch the headline we we don't need that anymore we don't
|
||
|
|
need the equal signs and we don't need the Bob Dev so I'm just cutting those lines and we get to
|
||
|
|
just play around really we get to just restructure this file so hello world exclamation underline
|
||
|
|
underline underline I like that version better I think that makes more visual sense so I'm going to
|
||
|
|
get rid of the introduction thing that Bob Dev wrote and then I'm going to choose to keep his
|
||
|
|
version of the welcome to get the stupid content tracker dot but I'm going to get rid of his
|
||
|
|
commentary afterwards so we're down to four lines hello world underline underline blank line welcome
|
||
|
|
to get the stupid content tracker I'll save that I'll close it and so now we've resolved the
|
||
|
|
conflicts that's that's how you resolve a merge conflict you just go into the file you edit it
|
||
|
|
such that there are no more conflicts marked and then you do a get it says to get commit the changes
|
||
|
|
so we'll do a get add 01 dot txt get commit and we'll put combining Bob Dev into master
|
||
|
|
so if we do a get log we see that we have a couple new entries so we have 76 we have
|
||
|
|
combining Bob Dev into master so that's what we just did and then we have delta fox trot one
|
||
|
|
Bob added some markdown so that was Bob's actual commit that was his that's him adding in his Bob
|
||
|
|
underscore dev and then we have 262 made the file prettier that was Alice's dev commit and then
|
||
|
|
we have one E4 Bob's first commit and D52 added a text file now is Alice done no Alice is not
|
||
|
|
done what is she not done yet she's not pushed so if we are in let's just make sure that where I
|
||
|
|
think we are we are we are in master so what we need what Alice would need to do at this point
|
||
|
|
to make sure that everyone gets her her changes is to do a get push origin head and now if we
|
||
|
|
switch back over to Bob and he is on Bob Dev right now which is fine so we'll just do a get fetch
|
||
|
|
and we see that yep sure enough there's new data on the on the server on the fake remote
|
||
|
|
one E4 to 76 master to origin master okay great so now if we do a cat of zero one dot txt it's still
|
||
|
|
Bob's version of the file with the markdown but he knows from his get fetch that there's new that
|
||
|
|
there was new stuff coming down from master so he's gonna see no he's not gonna see he's gonna
|
||
|
|
get checkout into master and then he's going to it says when I check out master it says switched
|
||
|
|
to branch master your branch is behind origin master by three commits and can be fast forwarded
|
||
|
|
use get pull to update your local branch okay sounds good let's do a get pull and we do a get
|
||
|
|
pull and it says it's updating from one E4 to 76 fast forward zero one dot txt three insertions
|
||
|
|
two deletions okay now cat oh one and it's it's the new version it's the combined version of
|
||
|
|
both both Alice and Bob so we'll do a get checkout of Bob underscore dev and we do a cat oh one
|
||
|
|
of dot txt and oh we're back to Bob's version okay so in this case rather than merging to master we
|
||
|
|
actually want to do the opposite we want to merge what what's in master the newest update stuff
|
||
|
|
updated stuff into our own branch could we just create a new branch based on master well sure
|
||
|
|
we could but no one would ever do that because then you know you'd have a branch for every time
|
||
|
|
master gets updated which would be weird so you can do a get merge Bob underscore dev space master
|
||
|
|
and it's telling me that there have been eight things three insertions and five deletions and then
|
||
|
|
if we do a cat zero one dot txt it looks like it is the combined version now hello world
|
||
|
|
exclamation under the line welcome to get stupid good content tracker great so we're we're up
|
||
|
|
to speed now if we do status it should tell us that uh... we're on branch Bob dev but our branch
|
||
|
|
is ahead of origin Bob dev by two commits hmm that's weird why would it why would it be ahead how can
|
||
|
|
something be ahead by two commits well the reason is because Bob dev hasn't been the we're now on
|
||
|
|
a new version of Bob dev and we haven't we haven't made these changes live yet so what we'll do
|
||
|
|
is do a get add dot so we're adding everything which is zero one dot txt and then we'll do a get
|
||
|
|
commit and we'll say merging latest updates from master into Bob dev and then we'll do a get push
|
||
|
|
origin head and now if we do a get status we see that we're on branch Bob dev and that our
|
||
|
|
branch is up to date with origin Bob dev there you go now we're now we're all in sync again
|
||
|
|
okay so what I was going to show you is that we could we could go back at this and we could do an
|
||
|
|
Emax oh one dot txt and we could go here to the bottom of the of the page and start adding some more
|
||
|
|
text to use get effectively listen to class use introduction to get on hpr okay so now we've
|
||
|
|
got a new line at the bottom of our online six of our of our file and he's going to add that he's
|
||
|
|
going to commit it linked or yeah referenced hpr and then we'll do a get push origin head
|
||
|
|
and we're good to go so now we'll go back over to Alice's place we'll see what branch she's on
|
||
|
|
she's on master still so let's get her back over on to Alice dev because that's where she does her
|
||
|
|
work oops tried to create a new branch I meant to say check out get check out Alice underscore dev
|
||
|
|
and now she wants to make some changes to this file but before she does that she would certainly
|
||
|
|
being a very good get user make sure that she her branch is up to date now if she does it get status
|
||
|
|
and this is where it kind of gets tricky sometimes you you see that she's on branch Alice dev but
|
||
|
|
her branch is as far as her branch knows up to date with origin Alice dev I mean that's true
|
||
|
|
and it's pretty common practice I think that when you're finished with a branch you basically ditch
|
||
|
|
the branch in this particular case she certainly could do that she could just do a get branch
|
||
|
|
dash d for delete Alice underscore dev and that would blow that away and why wouldn't she because
|
||
|
|
she's made her changes she's merged them into master she's basically done with this branch
|
||
|
|
and when your workflow is one branch per bug fix or one branch per feature ad then then that
|
||
|
|
really does make sense you can delete a branch when you're finished with it and then and then
|
||
|
|
you're just back on master and when you're ready to work again you make a new branch which
|
||
|
|
bases itself you know you branch off of master now Bob already showed you the the alternate way
|
||
|
|
of doing that which is to merge master into Bob Dev Alice is a little bit more experienced maybe
|
||
|
|
so she she's just gonna do exactly what I said that she could do so she's gonna go back over to master
|
||
|
|
she's gonna do a get branch dash d for delete Alice underscore dev and it has deleted that branch
|
||
|
|
now if we do a get branch we see that there's Bob Dev and there's master and she's going to create
|
||
|
|
a new branch she's gonna do a get checkout dash b for branch and she'll just call this Alice revision
|
||
|
|
she doesn't really have a very good naming scheme for her branches but without a bug tracker it's
|
||
|
|
kind of sometimes hard to to come up with a good naming scheme if you have a good if you have a
|
||
|
|
bug tracker a lot of times you can just name your branches you know some you know the some descriptive
|
||
|
|
string and then underscore the the number of the bug that you're fixing or that you're that you're
|
||
|
|
answering but anyway here we are so we're on the new Alice revision version of this of her workspace
|
||
|
|
and we're gonna do emax o1.txt and we see that that the what she believes is the current version well
|
||
|
|
certainly the current vert the latest version of master is here so she's not going to add a line
|
||
|
|
but if she is going to go in and say let's do let's get rid of that stupid content tracker
|
||
|
|
we'll just do welcome to get a full stop and then we'll do this is a version control system
|
||
|
|
of indeterminate intelligence there so she's changed a line she's changed line four
|
||
|
|
she hasn't added any lines she's altered one so now we're going to do a get add o1.txt we're going to do a
|
||
|
|
get commit-m added width and then we'll get push of course it's a new branch right so we have to
|
||
|
|
do a get push-u origin head and and once again we're back at that situation where we've got divergent
|
||
|
|
versions of this project so Mary no Alice rather whatever her name is is still the the project lead
|
||
|
|
so she's going to check out master and maybe she's going to merge get merge master with Alice
|
||
|
|
from Alice revision and that went through just fine so if I do a cat zero one then we see her new
|
||
|
|
version with the with the witty line four but the moment she tries to merge in something from
|
||
|
|
Bob that's when it's going to get fun so first she'll do a get fetch and she'll see when she does
|
||
|
|
the get fetch hey there's some new stuff on Bob underscore dev okay well that's interesting
|
||
|
|
to see so she can do a get checkout again of origin slash Bob dev because she doesn't want to
|
||
|
|
necessarily she she's fine with being in a detached state so she does a cat zero one dot txt
|
||
|
|
and she sees that he's added a line but that his line four is the old version of the line so he's
|
||
|
|
got six lines but line four is the old version everything up to from from line one to four is is the
|
||
|
|
old version so that that's going to cause some conflict so now she's going to check out she's
|
||
|
|
going to do the Bob get checkout Bob underscore dev which is her local version of Bob's branch
|
||
|
|
it tells her your branch is behind origin Bob but Bob dev by three commits and can be fast-forwarded
|
||
|
|
uses use get pool to update the local branch okay get pool and it looks like there are eight
|
||
|
|
changes that should sound familiar because that's what happened when Bob dev updated his from
|
||
|
|
from master so then we do and actually those are actually there's something different there but
|
||
|
|
anyway so we're going to do a cat oh one and yeah it's his new version so then she's going to
|
||
|
|
switch over to master and she's going to do oh get checkout master not get branch master and
|
||
|
|
then she's going to do a get merge and she knows that there's going to be a conflict so she's doing
|
||
|
|
this confidently get merge master from Bob dev and sure enough it says conflict merge conflicts
|
||
|
|
in oh one dot t x t so we open that up again and this is a little bit more interesting so we have
|
||
|
|
hello world underscore underscore underscore blank line and then we get the the head designator
|
||
|
|
and it says welcome to get this is a version control system of interterrant intelligence so
|
||
|
|
that's Mary's latest change that she merged with master then under that there is welcome to get
|
||
|
|
the stupid content tracker and then the the new line to use get effectively listen to class use
|
||
|
|
introduction and that's Bob's version so as you can see the common element that they that they're
|
||
|
|
that their file shared which was hello world is free to merge there's no problem there
|
||
|
|
the stuff that starts to get a little bit complicated are the the lines below that and that's more
|
||
|
|
often what you're going to see so we're going to keep Mary's witty line we're going to keep Bob's
|
||
|
|
final line about listening to me on hpr because why wouldn't I it's about me so we'll save it we'll
|
||
|
|
close and then she can do a get add oh one a get commit incorporated Bob's version about hpr
|
||
|
|
and then she will of course do a get push origin head and that way we next time Bob starts working
|
||
|
|
he'll be able to see that there are changes to master he'll be able to pull those changes
|
||
|
|
and merge them into whatever he's working on or at least merge them into his master branch
|
||
|
|
and continue on smartly of course we won't this episode is is long enough so I'll I'll end this
|
||
|
|
discussion of this intro to branching now and and I'll revisit it in the next episode because there's
|
||
|
|
more to talk about and I think when you start making commits like this one of the one of the obvious
|
||
|
|
questions maybe not right now as you're just listening to it but eventually you're going to think
|
||
|
|
well okay it's version control so how do I see the other versions how do I go back and forth
|
||
|
|
between versions how do I check out old versions how do I restore from an old version all those
|
||
|
|
kinds of questions a lot of that honestly is going to be stuff that you that you you come across
|
||
|
|
and you think oh my gosh I need to do this very specific thing I will search on the internet for
|
||
|
|
how to do it and then I will find a magical command that does exactly what I want and I will do
|
||
|
|
that and then you'll continue on your way however that doesn't mean you can't practice a little
|
||
|
|
bit beforehand and that's what we'll do next time don't miss it you've been listening to
|
||
|
|
hecka public radio at hecka public radio dot org we are a community podcast network that release
|
||
|
|
the shows every weekday Monday through Friday today's show like all our shows was contributed by
|
||
|
|
an hbr listener like yourself if you ever thought of recording a podcast then click on our
|
||
|
|
contributing to find out how easy it really is hecka public radio was founded by the digital
|
||
|
|
dog pound and the infonomican computer club and it's part of the binary revolution at binrev.com
|
||
|
|
if you have comments on today's show please email the host directly leave a comment on the website
|
||
|
|
or record a follow-up episode yourself unless otherwise status today's show is released on
|
||
|
|
creative comments, attribution, share a live 3.0 license
|