fetch

Pulling & Fetching Changes from a Remote [Learn Git Video Course]



Sharing buttons:

you

welcome to a video series on learning

version control with git today we'll see

how to download new changes from a

remote repository first it's important

to know that there are two different

commands for downloading changes fetch

and pull before we talk about the

differences between fetch and pull you

need to understand one thing

in order to see new remote data you need

to explicitly update I'll make an

example let's say you're working on a

project together with a teammate your

teammate then pushes his changes to the

common remote and here's the important

bit you will not know about this new

data on the remote until you explicitly

request it when you do so for example by

performing a fetch it makes a snapshot

of the data on the remote and it

downloads it to your local repository

this means that when you're looking at

branches or commits you only look at

that snapshot in your local repository

and this is only as fresh as your last

update

so if you should ever wonder why you

don't see your teammates new commits

it's probably because you're looking at

an old state and haven't updated yet as

said fetch downloads all the data from

the remote repository it saves it in

your local repository and this allows

you to see what happened on the remote

the other command is pull pull also

downloads new data but it also

integrates it directly into your working

copy it merges new commits into your

current head branch

the difference between the two fetch

only downloads new data from a remote

but it leaves your working copy

untouched fetches great to stay

up-to-date on what's new on the remote

you can then decide what you want to

integrate and what not pool also

downloads but it also directly

integrates new commits into your current

head branch you could describe it as a

fetch and a merge operation

let's do all of this in practice

first we need to get an overview of

where we are at the moment we can see

two branches a local master branch and a

master branch on the remote remember

that this information is only as fresh

as your last update I have good news

because by default tower fetches remote

data automatically in the background for

you you can configure how often this

should happen or even switch it off but

to illustrate the workflow let's do this

manually and perform a fetch operation

and there are indeed new commits on the

remote that we haven't integrated yet we

see this both in the sidebar

and in the history of our local branch

para marks and pushed or unpooled

commits with a little arrow icon it

tells us all this because we established

a tracking connection between our local

master branch and it's remote

counterpart let's integrate these

commits into our local version of the

master branch first we make sure we are

unmasked our currently the head badge

here confirms this then we click the

pull button on the toolbar thanks to our

tracking connection tower already

suggests that we pull from the origin

remote branch after executing this our

local master branch contains all the new

commits from the remote master because

earlier we made that fetch we also see

that there's a new feature sign-up

branch on the remote let's say we want

to start working on this topic

to do that we need to create a local

copy of that branch you cannot work on a

remote branch because working involves

files in your working copy and your

working copy always contains the files

of your local head branch

so let's create a local copy of the

remote feature signup branch

right-click that remote branch and

select the trek option alternatively you

can also just drag and drop it onto the

branches section header

this creates a new local branch that is

based on the remote one additionally it

has a trekking connection that makes

pulling pushing and staying up to date

much easier with this local version of

the feature sign up branch in place we

can now work on this feature

that's it for now thanks for watching

and see you soon