Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the advantage of using git fetch?

Tags:

git

When using git, what's the advantage of being able to fetch without necessarily merging/rebasing ? From this answer, I see that

This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files.

Do frequent fetches really make future merge less complicated or less likely to have conflicts ?

like image 603
blackbird Avatar asked Feb 08 '23 02:02

blackbird


1 Answers

what's the advantage of being able to fetch without necessarily merging/rebasing?

Well for one thing, what if you have nothing to merge or rebase yet? What if you want to check out somebody else's brand new branch that they've pushed to the remote? You're going to need to fetch in order to make your local Git aware of the new branch.

Do frequent fetches make future merge less complicated or less likely to have conflicts ?

No, that's got nothing to do with fetching. If you're just fetching but not merging or rebasing, then there is no reason to think you're helping out with future conflicts.

All fetch does is let your local Git repository see what's going on in your remote Git repository. It lets you see new branches and commit, and inspect changes that are ready to be merged into local branches without actually merging them.

It also lets you slightly optimize your work flow to reduce network hits. Each git pull involves a git fetch, so if you want to get pull on five different branches, you have four redundant extra git fetch calls. This isn't really a big deal, unless you're in a hurry: Suppose you're walking out of the office to catch your train, but you want to make sure you have all the changes from every branch available to you while working remotely. You can simply git fetch once while you're on the network, and then leave. Later, without a network connection, you can manually git checkout <branch>; get merge origin/<branch> to merge the changes you previously fetched.

like image 120
meagar Avatar answered Feb 14 '23 10:02

meagar