6

Since git fetch doesn't make any changes and it just updates the references and keeps the tracking branches up to date with the remote branches (like it says if it's ahead and/or behind).

I can see that it is really important to know whats going on on the remote repo.

If git fetch is not destructive. Why doesn't git just run a git fetch periodically whenever there is an internet connection?

Is it good practice to make a script that does that for me?

Mark Fisher
  • 965
  • 1
  • 11
  • 30
user3571278
  • 721
  • 5
  • 15
  • Git fetch copies any new commits from the remote to branches you are tracking _without_ merging them. Do you have any processes running automatically which would benefit from an auto `git fetch`? – Tim Biegeleisen Jun 02 '15 at 01:13
  • 2
    "I can see that it is really important to know whats going on on the remote repo." . . . except when it's not. If you've got a team all actively working on interdependent code, then sure, fetch from each other on a timer or whatever, but once a day or even once a week is more usual for work on independent parts. – jthill Jun 02 '15 at 02:24
  • 3
    Remember that Git doesn't impose a workflow on you. You might have zero remotes (so `fetch` is useless), or one hundred (which one(s) do you want to `fetch` from? Which branches? Do you really want to track all of them locally?) You might have a remote that's sometimes available and sometimes not, so auto-`fetch`ing will be difficult. Git is a flexible tool, and it tries not to assume things about your workflow. – ChrisGPT was on strike Jun 02 '15 at 02:37
  • @Chris, reckon this is worth putting in the answer – Biswajit_86 Jun 02 '15 at 03:49
  • @Biswajit_86, good point, but I think bcmcfc's answer sufficiently captures this. – ChrisGPT was on strike Jun 02 '15 at 17:14

1 Answers1

5

Essentially, what it boils down to is that Git provides a set of tools for you but leaves the rest of the details of how you actually use it up to the unique circumstances of the user.

This is why other projects such as git-flow have come about, that go that bit further and provide a tried and tested workflow that may work for a large number of users.

If you want to fetch regularly by all means write a cron that does so. That's where the power of git comes in - it's a solid set of tools and if you want to extend it in some way you can.

However, perhaps it's not such a good idea. How often is periodically? If you're about to push and your script last fetched a minute before a colleague pushed to the same branch, then it would reject your push and you'd have to fetch, pull, merge, rebase, etc. anyway.

bcmcfc
  • 25,966
  • 29
  • 109
  • 181