GIT VISUAL #1

Green has the repo “A” on GitHub; Blue wants to upgrade Green’s “A” repo with a new feature.

So let’s break this case down step by step.

1 FORK

Blue goes to “A” repo on Github and fork it. Now Blue has a version of the repo called “A.” Now both Green and Blue have their separated versions of the repo “A.”

2 GIT CLONE

Blue needs to clone the repo “A blue GitHub” to his machine; after getting the URL to clone on repo GitHub page, Blue runs the following code:

> git clone GITHUB_URL_A_BLUE

This will clone the repo from GitHub into his local machine, and this local repo has a REMOTE called ORIGIN connecting the local repo “A blue local” to the Blue’s “A blue GitHub”. Blue can PUSH/PULL/FETCH code to ORIGIN because Blue is the owner of the GitHub repo.

If Blue wants to check the remotes from “A blue LOCAL” repo:

> git remote

or

> git remote -v

3 ADDING REMOTES

Blue wants to check if the “A green GITHUB” repo was updated by Green. So Blue needs to add a new REMOTE connecting the “A blue local” repo to the “A green GitHub” repo. Blue needs to go the “A green GitHub” repo and get the URL of the repo. Blue will call this new remote as UPSTREAM:

> git remote add upstream GITHUB_URL_A_GREEN

Now “A blue local” repo has the following remotes:

ORIGIN(A blue GitHub): Because of this remote point to a repo that belongs to Blue. Blue can PUSH/PULL from this repo.

UPSTREAM(A green GitHub): Because of this remote point to “A green GITHUB” that belongs to Green, Blue can’t PUSH to this repo, but Blue can FETCH/PULL from this repo.

4 WORKING ON A NEW BRANCH

Blue creates a new branch on his local “A blue local” repo to add a new feature to the repo. Blue does this to keep the MASTER branch safe from modifications.

To create a new branch and change to it immediately run the command:

> git checkout -b [name_of_your_new_branch]BLUE WANTS TO CREATE A BRANCH CALLED UPGRADE:> git checkout -b upgrade

5 After finished the upgrade.

After finishing the upgrade, Blue needs to PUSH the “UPGRADE” branch to ORIGIN remote; so Green can see what Blue did.

> git push origin upgrade

After this, Blue is done!

6 Green Starts

Green looked on “A blue GitHub” and wants to upgrade “A green local” with Blue’s upgrade.

So now Green needs to ADD a REMOTE to PULL or FETCH the “A blue GitHub” UPGRADE branch.

> git remote add blue GITHUB_URL_A_BLUE

Now Green is ready to get the “UPGRADE” branch.

7 FETCH

With the new remote to “A green local”; Green can finally fetch the blue remote to downloads all the branches without merge it immediately.

> git fetch blue

8 MERGE

Now Green wants to merge the “A green local” master branch with the branch “upgrade” from the REMOTE Blue.
First, Green needs to go to the local master branch:

> git checkout master

Then Green runs the following command to merge the branch blue/upgrade into the master.

> git merge blue/upgrade

9 GREEN PUSH IT TO ORIGIN MASTER

Green pushes the master branch to ORIGIN/master

> git push origin master

10 JOB DONE!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store