blackbird
blackbird

Reputation: 1137

What's the advantage of using git fetch?

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 ?

Upvotes: 5

Views: 1198

Answers (2)

CodeWizard
CodeWizard

Reputation: 141946

Another aspect of git fetch which was not mentioned is that you can sync all your local repo with the remote repo by adding the following flags:

# update whole repository including branches, tags and
# with the --prune it will also remove teh deleted branches and tags
# from your local repository 
git fetch --all --prune

Upvotes: 1

user229044
user229044

Reputation: 239240

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.

Upvotes: 8

Related Questions