Git: automatic fetching from remote repositories?

Steve Bennett picture Steve Bennett · May 5, 2012 · Viewed 10.5k times · Source

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.

Answer

joshp picture joshp · May 5, 2012

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.