Steve Bennett
Steve Bennett

Reputation: 126527

Git: automatic fetching from remote repositories?

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.

Upvotes: 21

Views: 21537

Answers (3)

serv-inc
serv-inc

Reputation: 38247

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.

Upvotes: 11

Winter
Winter

Reputation: 368

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.

Upvotes: 6

joshp
joshp

Reputation: 1892

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.

Upvotes: 10

Related Questions