Тёмный

Git Fetch vs Git Pull? Which one should you choose? 

Cameron McKenzie
Подписаться 19 тыс.
Просмотров 38 тыс.
50% 1

Ever wonder about the difference between git fetch and git pull?
They both copy changes from the remote GitHub or GitLab repository to your local Git repo, but git fetch does not update your working directory while git pull does.
That's it, that's the difference between fetch and pull in Git.
On, and after you do a fetch, if you do want to update your local Git workingtree, then just do a git merge. That brings it all in.
In fact, git fetch followed by a git merge is basically the same thing as a git pull.

Опубликовано:

 

2 май 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 70   
@luispablosandovalcastro7452
@luispablosandovalcastro7452 Месяц назад
I've watched many tutorials about this today, but none of them was even close to this one. You're the boss
@cameronmcnz
@cameronmcnz Месяц назад
Why would you watch other videos???
@midlifecoding
@midlifecoding Год назад
WOW! This the easiest and yet most comprehensive explanation of this. Thank you!
@cameronmcnz
@cameronmcnz Год назад
Thanks for your kind words! I try to keep my videos short and to the point. This is actually a fairly advanced topic so hopefully I didn't overcomplicate it.
@ivanphone4917
@ivanphone4917 Год назад
Git fetch and pull has never been so simple to understand.
@joelpaul8650
@joelpaul8650 Месяц назад
No BS Straight to the point.
@cameronmcnz
@cameronmcnz Месяц назад
Yeah. The RU-vid algo doesn't like that. 🤣 Thanks for watching!
@nsharony
@nsharony Год назад
Very nice tutorial. Besides explaining the technical diff between fetch and pull, it woulc have been great if you could also explain the reasons why one would use git fetch
@cameronmcnz
@cameronmcnz Год назад
That's not a bad idea. I try and keep my videos brief and to the point, so I try not to frontload them with too much background. But I think that would be an improvement for the next video. I might add that to the article I did.
@billanderson4709
@billanderson4709 5 месяцев назад
@@cameronmcnz Yes it would be helpful with why. A lot of tutorials online just explain the how and not the why. When explaining the why, to me anyways I can understand it better on the how when the why/theory is explained. Maybe apply that to all tutorials even though you try not to frontload but I think it would be more beneficial to do so. Great video and thanks!
@XgigabyteX1
@XgigabyteX1 9 месяцев назад
I'm Brazilian and with your video I was able to understand the difference between one and the other, unfortunately in my language there is no well-explained content as well as in English. It's a shame that I'm not fluent in English, but the RU-vid translation helped me a lot, I had a little doubt about when to use git fetch, but it could be that you've already released another video. So in that case I will look at the other videos on your channel. I'm grateful -------------------- Just to recap, there is this type of content but in general context videos that are usually 1 hour long and you have to look for the video where it is talked about and generally a shallower explanation is given.
@edgaruriel9565
@edgaruriel9565 9 месяцев назад
thanks! this video is really helpful. greeting from México
@osa-_-
@osa-_- 29 дней назад
the way you talk is funny😂😂 but i like it, it was helpful thanks
@cameronmcnz
@cameronmcnz 29 дней назад
Might be my Canadian accent, or it might be some of the slightly exaggerated inflections I use in some of my words. I try to make my videos as entreating as I can, hopefully without being annoying.
@noel_curray
@noel_curray 11 месяцев назад
thank you for this clear explanation of fetch and pull. I appreciate the simple graphics and animation.
@cameronmcnz
@cameronmcnz 11 месяцев назад
Thanks! Just trying to keep my videos short and to the point. Nobody wants me wasting their time.
@roudiolding8023
@roudiolding8023 10 месяцев назад
Finally understood, thanks :DD
@official_youtube_1
@official_youtube_1 11 месяцев назад
no nonsense talking, right on point, This short and sweet video is legend
@MrLuffyMedina
@MrLuffyMedina 2 месяца назад
just what I needed, thank you
@cameronmcnz
@cameronmcnz 2 месяца назад
I love that this quick tutorial has resonated with so many people. Glad to help!!!
@MasharipovSaidbek
@MasharipovSaidbek Год назад
This is really nice and straight to the point lesson, thanks sir!
@cameronmcnz
@cameronmcnz Год назад
Glad to be of service! I always assume people know a bit about Git first, so I don't waste time over-explaining things. So if you enjoyed this, you're obviously already a pretty smart cookie. Thanks again for the kind words!
@Syktox
@Syktox 9 месяцев назад
I like your video :D
@cameronmcnz
@cameronmcnz 9 месяцев назад
Glad I could help!
@user-zh2oz9fe4m
@user-zh2oz9fe4m 10 месяцев назад
That was pretty well explained! Thanks a million!
@cameronmcnz
@cameronmcnz 10 месяцев назад
Happy to be of service! Once you get this down, the whole collaborative git push, pull and fetch stuff becomes super easy!
@davidjhons2549
@davidjhons2549 8 месяцев назад
its perfect explanation in very short time...Appreciate it😊
@cameronmcnz
@cameronmcnz 8 месяцев назад
I try my best to get to the point. Nobody wants to hear my thoughts on world politics.
@mibrahim4245
@mibrahim4245 Год назад
thank you, but I have a rly important question; suppose I work on branch1 and my teammate works on branch2 .. and I wanted to see his work on my local machine and I did "git pull" .. as you said that `git pull` will do the merge also, so, what if now I did something on my branch `branch1` and I pushed it to the remote .. what will happen to branch2 ? will it be overwritten by the version I have "the version that I downloaded at the time I did git pull " ?
@ivanphone4917
@ivanphone4917 Год назад
It’ll only merge the same branch. You are safe to do a pull. Then to see his work do a git switch and you can see the work. Then u can switch back to yours.
@mibrahim4245
@mibrahim4245 Год назад
@@ivanphone4917 thank you for the answer, but could you clarify more.. If I did `git pull`, this should merge his branch `branch2` with my current branch `main`, right? .. Then what if I commit a change on the main branch and push it, this will push the changes I made on the main + branch2 that I pulled .. is that correct or I missed something
@mibrahim4245
@mibrahim4245 Год назад
@@ivanphone4917 aah or u mean that it will merge branch1 with branch1 and branch2 with branch2 and so on ... ?
@janbaumeister8263
@janbaumeister8263 2 месяца назад
@@mibrahim4245 aah or u mean that it will merge branch1 with branch1 and branch2 with branch2 and so on ... ? - yup
@Roamer_sea_manila
@Roamer_sea_manila 8 месяцев назад
Amazing. Thank you and nice video. So does everyone use only pull? I can't understand why just fetch and hace the files in the repo and not see and use the files.
@cameronmcnz
@cameronmcnz 5 месяцев назад
One reason to use fetch is to just find out how far ahead or behind you are from the master branch. When you do a fetch, you can then do a 'git status', and Git will say "The server is 10 commits ahead of you" or "You are 12 commits ahead of the server." Just another reason to use fetch.
@Hinkakan
@Hinkakan 8 месяцев назад
Great vid, thanks. So in the limbo, between FETCH and MERGE, where does the file exist? Which branch?, where does the MERGE command merge FROM?
@cameronmcnz
@cameronmcnz 8 месяцев назад
After the fetch, the 'remote tracking branch' in your local repo is updated. When you do the merge, the 'remote tracking branch' is merged with your local branch. That's why if you do a git branch -a command, you'll see branches like: /remote/main /remote/development Those branches track the changes on the remote repo.
@Hinkakan
@Hinkakan 8 месяцев назад
@@cameronmcnz aha! Thanks for the clarification
@namkha2000
@namkha2000 3 месяца назад
Is there a way to download a specific branch to the local computer? cloning with URL always get the "main" version
@cameronmcnz
@cameronmcnz 3 месяца назад
Here's an article I wrote on how to clone a specific branch: www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-git-clone-a-specific-branch-only
@adityapradhan7201
@adityapradhan7201 9 месяцев назад
What is the advantage /use case of git fetch over git pull? Ultimately as I understand one has to merge after git fetch right?
@cameronmcnz
@cameronmcnz 9 месяцев назад
Pull might cause a conflict if you are working on the same branch as someone else. You pull their changes and it tries to overwrite your local files in your workspace and you might get a merge conflict. A fetch won't do that. Also, fetch will update other branches that might have changed. So a fetch just lets your local environment know about other branches that have updates without messing with your local files. Then you can switch to those updated branches or even merge those updated branches with your local workspace. Kinda like that. In this video I didn't talk about multiple branches on the server being updated. I stuck with the simple one-branch scenario to keep it simple.
@adityapradhan7201
@adityapradhan7201 9 месяцев назад
@@cameronmcnz That made total sense to me. Thank you for elaborate reply :)
@cameronmcnz
@cameronmcnz 9 месяцев назад
Glad I could help!!!
@moveonvillain1080
@moveonvillain1080 2 месяца назад
So if I have develop branch and I have a feature branch I am working on. So to synchronise my feature branch with latest changes from develop branch I should just git pull while I am in my feature branch ?
@cameronmcnz
@cameronmcnz 2 месяца назад
The pull will update your local repository about the changes in the develop branch, but it won't merge those changes if you're on the feature branch. You always have to do a merge to bring in changes from one branch to another. The fetch or pull will simply tell your local repo about the changes to those other branches.
@moveonvillain1080
@moveonvillain1080 2 месяца назад
@@cameronmcnz thanks for clarification
@cameronmcnz
@cameronmcnz 2 месяца назад
@@moveonvillain1080 My pleasure. It all starts making sense once you've done it a few times. Now be careful with those merge conflicts!
@ertanyildiz-ip6cy
@ertanyildiz-ip6cy 6 месяцев назад
awesome.
@crescenstan7167
@crescenstan7167 9 месяцев назад
short and sweet. thanks!
@cameronmcnz
@cameronmcnz 9 месяцев назад
I try my best to get to core topic quickly and not waste your time. Glad I could help!
@airguy5964
@airguy5964 3 месяца назад
best explanation, thx
@cameronmcnz
@cameronmcnz 3 месяца назад
Thanks! I tried to keep it short and to the point. I probably could have added a bit about how a fetch will update 'tracking branches' and let you know how far ahead or behind you are from branches on GitHub or GitLab. But I tried to just stick to the basics. Thanks for watching and subscribing!
@AtulShegokar
@AtulShegokar 6 месяцев назад
Man you are really awosome & happy. Lots of love💌
@cameronmcnz
@cameronmcnz 6 месяцев назад
Glad to be of service. I love Git!
@ivanfigueroa2932
@ivanfigueroa2932 9 месяцев назад
I'm confused, what is the difference between local repository and working directory?
@cameronmcnz
@cameronmcnz 9 месяцев назад
The working directory is where your files are on the local filesystem. You can edit, delete and change those files and it won't impact the local Git repository until you do a commit. The Git repository keeps a history of all your commits and other information like branch names and how to connect to GitHub. So the working directory is just the files you're currently working on.
@stefangheorghe5271
@stefangheorghe5271 Год назад
What and where is "local repository"?
@cameronmcnz
@cameronmcnz Год назад
The local repo gets created when the git clone happens. The git clone command creates a folder that matches the name of the repo on your local machine. That folder contains a hidden folder named .git. The whole repo is in there, although that's not a folder you're supposed to mess around with.
@rafaeldacosta8581
@rafaeldacosta8581 29 дней назад
0:35 I came to learn pull push merge fetch, because I am messing up my codes when syncing and I end up learning it's possible to enter a directory using an wildcard 😂 "cd p*"
@cameronmcnz
@cameronmcnz 29 дней назад
It really is a nice trick!
@harshadudapure
@harshadudapure 8 месяцев назад
Thank you!!👍
@cathalsurfs
@cathalsurfs Год назад
And... BOOM this has to be the WORST explanation ever!!!! BOOOMM!!!!
@cameronmcnz
@cameronmcnz Год назад
Why do you say that?
@cameronmcnz
@cameronmcnz Год назад
@niyaz4013 Everyone's a critic. 🤷‍♀
@computerarchitecture484
@computerarchitecture484 Год назад
wow it's wonderful.
@cameronmcnz
@cameronmcnz Год назад
Thanks for your kind words! I try to keep these videos short, but I think maybe I could have put a bit of an explainer at the start telling people where I was going. Always trying to do better!
@Mad_MonkEE
@Mad_MonkEE 5 месяцев назад
BOOOOOOOOOOM
@cameronmcnz
@cameronmcnz 5 месяцев назад
I like my booms. :) Thanks for watching!
@anarmammadovn
@anarmammadovn 2 месяца назад
Brilliant explanation. I think each of every git tutorial explain like this. Thank's btw you saved my life.
Далее
Git Tutorial For Dummies
19:25
Просмотров 1 млн
Git Rebase Vs. Merge
19:59
Просмотров 106 тыс.
Git PULL vs FETCH
7:13
Просмотров 9 тыс.
How Git Works: Explained in 4 Minutes
4:18
Просмотров 154 тыс.
GIT: Merge or Rebase? What's the difference?
10:47
Просмотров 133 тыс.
Git Fork vs. Git Clone: What's the Difference?
9:41
Просмотров 72 тыс.
tRPC, gRPC, GraphQL or REST: when to use what?
10:46
Просмотров 72 тыс.
Git clone, push, pull, fetch. Основы git
8:25
Просмотров 43 тыс.
Git revert vs reset: What's the difference?
8:15
Просмотров 4,1 тыс.
13 Advanced (but useful) Git Techniques and Shortcuts
8:07
How GIT works under the HOOD?
16:01
Просмотров 188 тыс.
Unlock Git collaboration with CLONE, PUSH & FETCH
9:09