Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 847
Steve Bennett Avatar asked May 05 '12 17:05

Steve Bennett


People also ask

How do I fetch from a remote repository?

If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.

Does git pull pull from remote?

The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows.

Does git checkout also fetch?

In review, git fetch is a primary command used to download contents from a remote repository. git fetch is used in conjunction with git remote , git branch , git checkout , and git reset to update a local repository to the state of a remote. The git fetch command is a critical piece of collaborative git work flows.


1 Answers

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.

like image 153
joshp Avatar answered Nov 15 '22 13:11

joshp