So now I'm going to demonstrate this fork and clone workflow on very, very simple terms.
But the workflow is the same.
We're just going to work on a very silly repository.
So as Colt one GitHub user, I'm going to make a new repository and I'm not going to give anybody access.
I'm going to make it public, of course, but I'm not going to make anybody a collaborator.
So nobody will be able to push to this.
I'll just call this fork and clone, maybe fork.
Jase and clone.
All right, it's public.
I'll put a read me in there and then I'll create this repository.
Okay.
So now I'm going to just add, I have my initial commit, maybe I'll do one more commit.
I'm just going to do it on GitHub to keep things simple.
So this.
Is a repo to demonstrate the fork and clone workflow.
Sure we'll commit those changes to the main branch.
And there we are.
So the next thing that I'm going to do is change people.
I'm going to switch over to Stevie.
Pretend I'm Stevie.
So here we are on Stevie's GitHub.
I'm logged into Stevie here.
Stevie checks.
And if I go look at cults, repositories hate looking at this I can see forking clone.
So this is the original project.
I don't have access, I can't edit things.
I mean, I can view it because it's public and I do want to collaborate, but say I want to, I don't
know, I'll add some changes, I'll make a new file, whatever it is, there's some change that I want
to work on and suggest.
So I'm going to fork this repository as Stevie.
So instead of Colt slash, fork and clone, hopefully we end up with Stevie Chick's slash fork and clone
and it takes a moment.
But when it's done forking, there we are.
I now am going to copy this URL and clone this as Stevie.
So over here, let me clean this up a bit.
Okay.
So I'm Stevie here.
I'm going to back out.
Sure.
I'll just clone it right here.
Make sure I'm not in a repo.
Get clone that URL.
Excellent.
So now we have this fork in clone repository.
Very simple single commit.
No two commits in there from Colt Steel.
And now I have cloned it.
But if I look at my remote, I cloned the fork.
So that remote is just pointing to my fork, not to the original.
So I can push changes up.
I can do that right now if I wanted to.
But before that I'm going to just set up a second remote.
And the reason for this, if I go back to my diagrams, is that I also want to be able to get changes
that Colts might publish on the original project.
Because my fork is frozen in time.
I don't get changes from the original project.
After I create the fork they are forking, they diverge, right?
So if I want to stay up to date with what's happening and I want to get those changes on my repo from
Colt's original, then I want to have a connection.
I need a remote to refer to that original project repo so I'll just go to the original.
So this is the original project.
I'm going to copy this URL for Colt's version.
All right.
And then I'm going to add a remote.
So it's git remote add, and then I'm going to call this one upstream because that's really common name
or original or something to indicate this is the original thing I, I forked in clone.
This is not my repository so I'll just go with upstream.
So now if I do get remote V we have two remotes.
I know it's kind of hard to see them here because they're not on one line.
Let's make that full screen.
Here we are.
Origin goes to Stevie Nicks.
Upstream goes to Colt's version.
Okay, so now I'm switching back to Colt for a moment.
Let's suppose that during all of this, this a couple of minutes while Stevie has been forcing and cloning,
I'm working on this project as well.
And again, I'm just going to do a very silly, simple change.
I'm going to edit this, which we put in here for can.
I.
How about this?
My.
My favorite ice cream flavors.
And then we'll do in no particular order.
Mint.
Well, my actual favorite is peppermint.
That's not that common.
And then I'll say mint chip, and then let's just leave it at that for now.
All right, so there's my new commit.
I'll go with add ice cream to read me.
Commit changes to Main.
So this is happening on Colt's original repository.
Stevie's Falk doesn't have that.
They diverged.
They're not in sync anymore.
This is a fork from a moment in time, so they're not attached.
However, I can still get those changes because locally I have those two remotes.
So if I want the latest, it's just make sure it gets status.
Everything's up to date with origin, but if I want the latest from Colt's repository, I can do a get
poll and then the remote is upstream and then whatever branch I'm looking for, I want main so I'll
pull down from upstream and if I do a quick git log we see we have ice cream now add ice cream to read
me.
So now I could make some more changes on this potentially like let's say, what would I want to do if
I just open it over here in my text editor here's the read me file.
Let's do something like Steve's favorite.
Ice cream flavors.
And then Stevie is a chicken.
So Stevie really likes mealworms, maybe like shrimp flakes and sunflower seeds.
Och so we make a change, we'll add that commit so get add read me I'm doing this all as Stevie blocking
that but I'm all I'm working at Stevie the chicken right now so get commit let's do something like add
Stevie's Stevie fave ice cream not a great message but trying to keep this quick so if I want to make
a suggestion to the original project that they include this this new commit that I've made or whatever
multiple commits.
First of all, normally we'd be working on a branch and we are in a branch, but we'd work on a separate
branch, a feature branch, just to keep it simple.
I'm just working on Main as well, so I don't have permission to push this up to upstream, but I do
have permission to push to my fork.
So that's what I'm going to do.
Remember that my fork I labeled well, I didn't label, but the default name for that remote is origin.
Make that full screen as Stevie.
This is what I can push to.
I'm not allowed to push to this.
I don't own it.
I don't have collaborator privileges.
So I'm going to push up to Origin, get push, and then we'll do Origin.
And then Main is just the branch we're working on.
And when that finishes, I should be able to refresh on my fork as Stevie checks and we see Stevie's
flavors are down there but at the original does not have it.
So you can see I am one commit ahead of Colt's version if we just open that in a tab.
This is what Colts original version looks like.
So we we now have this work that we could suggest, and that's exactly what I'm going to do.
I'm going to open a pull request.
That's the next step in this diagram.
Should we make our changes, we push them up to our fork and then I pull request I make a pull request
to the original project.
So as Stevie, I'm going to make that pull request.
Thankfully, it's a very easy one to merge.
I'm going to ask.
Please, please allow this in.
Please.
I'm just a little chicken.
I want to make this PR.
Bock.
All right.
So then I'm going to create, pull, request.
Take a look here specifically.
I'm going from main to main.
That's not that common.
Normally we'd be working on a feature branch.
We saw how to make a pull request from a feature branch in the last what a couple of videos ago.
So it's the same process.
You just change the branch.
We just don't have a different branch to pick from right now.
So from my fork to the original main to main, here's my comment, please.
Here's my pull request.
All right, so I can't merge that in.
I don't have access.
I'm not the decider, but I just wait here and I hope that I hear back maybe some feedback.
I hope it's not just closed, but it may be.
Now as Colts, I'll go to pull requests, I'll refresh and we should see a new poll request.
And here it is.
I am the only person in charge I get to review and decide if I want to merge this in or not.
And let's say that I'm happy with it, so I will merge it in.
Confirm.
Now I have successfully merged in that poll request, so that means that fork and clone on my account.
Colt now has the new information from Steve's.
And so now we have completed this cycle at least one time.
So Steve made some changes, push them to the fork, made a pull request, the pull request was accepted
and merged in.
And so now this original repository has Steve's changes.
So this process is all over the place with open source development.
If we just take a look at any big git repository, let's take a look at here's react.
We can see lots and lots of contributors, I mean, used by millions of people.
And if I go to pull requests.
I showed this a while ago.
Lots and lots of pull requests.
And if we look at where the pull requests are originating from, let's just pick any of them.
It doesn't really matter.
Sure.
This one.
Notice that it says this person already pennacchio wants to merge one commit into Facebook master branch
from Ari's particular fork and then a feature branch.
So notice the prefix, right?
Facebook master versus Ari per.
Sorry if you're watching this, Ari, you're probably not watching this.
But anyway, that's a fork.
So this is a fork that was made and we can go take a look.
Here is that fork.
This is Ari's fork of the original React.
And they made a pull request and now they're just waiting their.
Yeah, well, they're not even just waiting.
There's a conversation happening about this poll request, but it's still open.
So that's the basic workflow and that's how all of these contributors are making their contributions.
They're forking and then making a pull request over with their changes and then to stay up to date with
what actually changes on the official repository.
Remember this step pulling down to get the latest changes from the official project repo so that you're
up to date with the work everyone else has merged in.