git fetch and remote tracking branch demonstration

Sharing buttons:

hello everyone today I want to talk

about git fetch it fetch was a command

which I never really understood meaning

I never really got what habit in the

background so I took a look and the

information I found is what I want to

share in this video right now so please

enjoy and don't hesitate to ask any

questions in the first step we are going

to create our local repository which

only consists of one commit on the

master branch in the second step we are

going to add our remote repository which

will be placed on github calm the third

step is going to be to synchronize both

repositories by pushing the local

repository to the remote repository

while we are on github we are going to

add an additional file using the github

page and make a commit out of it thus we

are actually ending up with both

repositories being out of sync with each

other this problem we are going to solve

in the fifth step while executing the

command git fetch this will be the point

where we are going to take a look at

what git fetch actually does and how we

can use it to synchronize both

repositories again so let's start out in

our terminal the initial git repository

consists of one file called file a and

to git ignore file by taking a look at

the git log we see that both files have

been committed and this makes our first

commit to the local git repository in

the next step we are going to create the

remote repository which is going to be

put on github visiting the github site

we are presented with this dashboard at

the bottom you see this button called

new repository which will represent our


repository so let's create it in this

example I'm going to call the remote

repository gift

fetch demo and we are going to create it

github is providing us this URL with

which we can basically synchronize the

remote repository and the local

repository we have already setup

therefore we are going to copy this URL

and go back to the terminal on the

terminal we are going to specify the

remote repository and thus adding the

capability to synchronize the local

repository with the remote repository we

can do this by using the command git

remote add which lets us add the remote

repositories which we are going to use

for synchronization after the add we

have to specify a name for the remote

which we can use as a shortcut later on

in our case we are going to use origin

which is the most commonly used one

after what we are going to paste the URL

we just copied from github now let's

take a look at the following command git

branch dash a is going to list all

available branches we are seeing that

the only available branch is the master

branch which represents our local

repository in the next step we are going

to push this local repository to our

just added remote one therefore we are

going to use git push followed by the

name of the remote we just edit so

origin and the branch we are going to

push which in our case is the only one

available the master branch

now let's go back to the github page and

see what happened we are seeing that

both files have been committed and

everything seems to be in sync right now

so in order to introduce an additional

commit we are going to add a file to the

remote repository and sync it with the

local repository later on therefore we

are going to click this link or this

little icon let's call this file file

beam introduce some text and say edit

file be to remote repository coming back

to the overview page we can see that

this remote repository is holding two

commits right now so let's go back to

our local repository and by typing git

log we can see that nothing changed yet

so basically the local repository is not

synchronized with the remote repository

this is what we are going to change in

the next step

therefore we are going to type git fetch

origin master which just means we are

going to fetch the current master branch

state from our Origin remote repository

on the left we are seeing that our

folder or local repository didn't change

it all yet this for me raised the

question where did the fetch end up

basically so since we did fetch

something down from our remote

repository where is it

that was the question I asked to myself

so that's basically what this video is

about so to explain that we are going

to see which branches are no available

to us we are seeing that our remote

branch of course is available and our

remote branch or remote trekking branch

rather it's basically the one who holds

now this fetched data we just fetched

from the remote repository

it is now locally available but it

remains in the remote tracking branch

and it's not yet merged into our local

master branch we can see this by typing

a gate lock origin master and we see

that it now holds two commits the one we

created locally in our local repository

and the one which we created remotely on

the remote repository so let's go back

in order to combine or synchronize or

merge both branches I'm going to use the

git merge command this is pretty

explicit I'm saying I'm going to merge

whatever is in the remote tracking

branch called

origin it's its master branch and I'm

going to merge it into my local master

branch which I don't have to specify

because yeah it's the branch

I'm currently have checked out yeah get

did a fast-forward in this case which is

some sort of merge I might explain later

on what this actually means but we can

basically see our git log that now the

second commit is also part of our local

repository and basically

repositories are in sync now so yeah

that's basically it hope you enjoyed the

video and if you have any questions

regarding what we just did feel free to

put it in the comments see you in the

next video