No video

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

  Рет қаралды 41,432

Cameron McKenzie

Cameron McKenzie

Күн бұрын

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.

Пікірлер: 87
@luispablosandovalcastro7452
@luispablosandovalcastro7452 2 ай бұрын
I've watched many tutorials about this today, but none of them was even close to this one. You're the boss
@cameronmcnz
@cameronmcnz 2 ай бұрын
Why would you watch other videos???
@leandroreis88
@leandroreis88 13 күн бұрын
Straightforward. That's the kind of content I've been looking for. Thx man.
@cameronmcnz
@cameronmcnz 13 күн бұрын
I try to keep things short and to the point. Nobody wants to hear my views on world politics, and people interested in fetch vs pull probably don't need an introduction to what Git is. Glad you enjoyed it!
@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 7 ай бұрын
@@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!
@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 3 ай бұрын
No BS Straight to the point.
@cameronmcnz
@cameronmcnz 3 ай бұрын
Yeah. The KZfaq algo doesn't like that. 🤣 Thanks for watching!
@hieulequang3000
@hieulequang3000 Ай бұрын
Thank you so much for this explanation, I have seen so many other but i couldnt understand this until i get to you.
@cameronmcnz
@cameronmcnz Ай бұрын
Thanks for the kind words! Git is really well thought out, and it all makes sense when you start to realize what it's doing under the hood!
@OmPrakash-vt5vr
@OmPrakash-vt5vr 16 күн бұрын
Its so simple. Thank you for concise and useful tutorial
@osa-_-
@osa-_- 2 ай бұрын
the way you talk is funny😂😂 but i like it, it was helpful thanks
@cameronmcnz
@cameronmcnz 2 ай бұрын
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 Жыл бұрын
thank you for this clear explanation of fetch and pull. I appreciate the simple graphics and animation.
@cameronmcnz
@cameronmcnz Жыл бұрын
Thanks! Just trying to keep my videos short and to the point. Nobody wants me wasting their time.
@renevillela129
@renevillela129 4 күн бұрын
Thank you very much. Straight to the point.
@XgigabyteX1
@XgigabyteX1 10 ай бұрын
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 KZfaq 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.
@official_youtube_1
@official_youtube_1 Жыл бұрын
no nonsense talking, right on point, This short and sweet video is legend
@user-mm7rz1zf3r
@user-mm7rz1zf3r Ай бұрын
Very good and clear explanation... awesome ... make more videos
@cameronmcnz
@cameronmcnz Ай бұрын
Nobody watched the 500 videos I've already made! 🤣 Thanks for the kind words. You put a big smile on my face going into the weekend!
@MrLuffyMedina
@MrLuffyMedina 3 ай бұрын
just what I needed, thank you
@cameronmcnz
@cameronmcnz 3 ай бұрын
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!
@umutdegismen
@umutdegismen 4 сағат бұрын
Thanks for the great explanation! A question; what is the point of using git fetch if we won't see it in our local machine ? We can pull it later instead of merge it later ?
@cameronmcnz
@cameronmcnz 3 сағат бұрын
One important reason, which I wish I mentioned in the video, is that it lets you know how far ahead or behind you are from the remote branch. A git status may say you are 4 commits ahead, then you do a git fetch, and it will tell you that you are actually 5 commits behind. So that's one very helpful use of git fetch. From there, you can perhaps cherry-pick things you want to bring in and do other things with references to those commits.
@AtulShegokar
@AtulShegokar 7 ай бұрын
Man you are really awosome & happy. Lots of love💌
@cameronmcnz
@cameronmcnz 7 ай бұрын
Glad to be of service. I love Git!
@roudiolding8023
@roudiolding8023 11 ай бұрын
Finally understood, thanks :DD
@Hinkakan
@Hinkakan 10 ай бұрын
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 10 ай бұрын
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 10 ай бұрын
@@cameronmcnz aha! Thanks for the clarification
@davidjhons2549
@davidjhons2549 10 ай бұрын
its perfect explanation in very short time...Appreciate it😊
@cameronmcnz
@cameronmcnz 10 ай бұрын
I try my best to get to the point. Nobody wants to hear my thoughts on world politics.
@edgaruriel9565
@edgaruriel9565 11 ай бұрын
thanks! this video is really helpful. greeting from México
@user-zh2oz9fe4m
@user-zh2oz9fe4m Жыл бұрын
That was pretty well explained! Thanks a million!
@cameronmcnz
@cameronmcnz Жыл бұрын
Happy to be of service! Once you get this down, the whole collaborative git push, pull and fetch stuff becomes super easy!
@Syktox
@Syktox 10 ай бұрын
I like your video :D
@cameronmcnz
@cameronmcnz 10 ай бұрын
Glad I could help!
@Roamer_sea_manila
@Roamer_sea_manila 10 ай бұрын
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 6 ай бұрын
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.
@crescenstan7167
@crescenstan7167 11 ай бұрын
short and sweet. thanks!
@cameronmcnz
@cameronmcnz 11 ай бұрын
I try my best to get to core topic quickly and not waste your time. Glad I could help!
@namkha2000
@namkha2000 5 ай бұрын
Is there a way to download a specific branch to the local computer? cloning with URL always get the "main" version
@cameronmcnz
@cameronmcnz 5 ай бұрын
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
@ivanfigueroa2932
@ivanfigueroa2932 10 ай бұрын
I'm confused, what is the difference between local repository and working directory?
@cameronmcnz
@cameronmcnz 10 ай бұрын
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.
@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 3 ай бұрын
@@mibrahim4245 aah or u mean that it will merge branch1 with branch1 and branch2 with branch2 and so on ... ? - yup
@airguy5964
@airguy5964 5 ай бұрын
best explanation, thx
@cameronmcnz
@cameronmcnz 5 ай бұрын
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!
@adityapradhan7201
@adityapradhan7201 10 ай бұрын
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 10 ай бұрын
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 10 ай бұрын
@@cameronmcnz That made total sense to me. Thank you for elaborate reply :)
@cameronmcnz
@cameronmcnz 10 ай бұрын
Glad I could help!!!
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 19 күн бұрын
I tried fetch, but it didn't bring important changes for me, so I forgot the command.
@cameronmcnz
@cameronmcnz 19 күн бұрын
It's designed not to actually change your workspace. But for example, the server gets 10 commits ahead of you. If you do a git status, without a fetch, Git may say you are at the same commit, or mayb even that you are ahead. If you do a fetch, Git will know if you are ahead or if the server is ahead the next time you do a git status. So it's a safe command that helps sync you with what's going on with GitHub or GitLab.
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 18 күн бұрын
@@cameronmcnz Thanks.
@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.
@saidurme
@saidurme Ай бұрын
cool one :)
@user-fb2xh2km6b
@user-fb2xh2km6b 26 күн бұрын
If there is an origin branch, how do I modify to use git pull origin?
@cameronmcnz
@cameronmcnz 26 күн бұрын
origin is implied now in git pull and git push, so you don't need to specify it.
@moveonvillain1080
@moveonvillain1080 3 ай бұрын
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 3 ай бұрын
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 3 ай бұрын
@@cameronmcnz thanks for clarification
@cameronmcnz
@cameronmcnz 3 ай бұрын
@@moveonvillain1080 My pleasure. It all starts making sense once you've done it a few times. Now be careful with those merge conflicts!
@rafaeldacosta8581
@rafaeldacosta8581 2 ай бұрын
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 2 ай бұрын
It really is a nice trick!
@ertanyildiz-ip6cy
@ertanyildiz-ip6cy 7 ай бұрын
awesome.
@harshadudapure
@harshadudapure 9 ай бұрын
Thank you!!👍
@deeptisharma9154
@deeptisharma9154 Ай бұрын
Why do we need git fetch......seems like its of no use
@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. 🤷‍♀
@Mad_MonkEE
@Mad_MonkEE 6 ай бұрын
BOOOOOOOOOOM
@cameronmcnz
@cameronmcnz 6 ай бұрын
I like my booms. :) Thanks for watching!
@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!
@anarmammadovn
@anarmammadovn 3 ай бұрын
Brilliant explanation. I think each of every git tutorial explain like this. Thank's btw you saved my life.
Git PULL vs FETCH
7:13
The Modern Coder
Рет қаралды 15 М.
Git Branching and Merging - Detailed Tutorial
54:28
SuperSimpleDev
Рет қаралды 200 М.
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 47 МЛН
🩷🩵VS👿
00:38
ISSEI / いっせい
Рет қаралды 17 МЛН
Kind Waiter's Gesture to Homeless Boy #shorts
00:32
I migliori trucchetti di Fabiosa
Рет қаралды 11 МЛН
How Git Works: Explained in 4 Minutes
4:18
ByteByteGo
Рет қаралды 184 М.
Git Fork vs. Git Clone: What's the Difference?
9:41
Eye on Tech
Рет қаралды 75 М.
Local vs. Remote Repositories in Git
1:57
Expero
Рет қаралды 6 М.
GIT: Merge or Rebase? What's the difference?
10:47
Front-end Science із Сергієм Пузанковим
Рет қаралды 135 М.
Unlock Git collaboration with CLONE, PUSH & FETCH
9:09
The Modern Coder
Рет қаралды 4,3 М.
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 1,1 МЛН
Difference between git PULL and git FETCH
3:40
Solo Kevin
Рет қаралды 46 М.
Git MERGE vs REBASE
16:12
Academind
Рет қаралды 1 МЛН
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 47 МЛН