21

One irritating thing I find about using command line Git is having to manually sync my repository with remote repositories. I constantly get tripped up by commands like "git status" that I (mistakenly) expect to report the difference between my working directory and a repository on GitHub. (Of course it reports the difference between my working directory and my local repository...)

Is there any way to get automatic/implicit fetching, so that remotes are always up to date? I would happily pay a penalty of a few seconds for commands like git status, git merge etc.

Steve Bennett
  • 114,604
  • 39
  • 168
  • 219

3 Answers3

10

One of those commands is already built in.

git pull

does a fetch and a merge.

For the other one, well....define your own command, such as

alias gitfu='git fetch; git status'

The shell is yours to command.

Depending on your configuration you may be asked for pass phrase or credentials for each of these.

joshp
  • 1,886
  • 2
  • 20
  • 28
8

In zsh, there is the git-auto-fetch plugin which

Automatically fetches all changes from all remotes while you are working in git-initialized directory.

Just add to your plugins in .zshrc.

serv-inc
  • 35,772
  • 9
  • 166
  • 188
6

If you would prefer to use a GUI like SourceTree, there's a preference option that checks default remotes every X minutes.

You could also set global alias in the global .gitconfig file under [alias]. Such as git fetch --all && git status (add -s for short status). Or possibly git stash && git pull && git stash apply && git status et al, if you currently have changes. But watch out for merge conflicts.

Winter
  • 368
  • 4
  • 15
  • Yeah, I'm actually not looking for a GUI solution. But I sure would like to streamline the Git cmd-line experience. – Steve Bennett May 06 '12 at 12:48
  • I thought [this Peepcode video about Advanced Git](https://peepcode.com/products/advanced-git) was pretty good. [This dotfiles guide](http://dotfiles.github.com/) although not just git commands may stir some ideas as well. – Winter May 06 '12 at 20:33