Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default remote for git fetch

Tags:

git

git-fetch

If I am on a local branch that is not tracking any remote branch and I give the command

git fetch

Given I have several remotes defined in $GIT_DIR/config, from which remote is the fetch done?

I tried to find out from the man page, but this point is unclear to me.

Additionally: How can I change this default remote without making the local branch tracking?

like image 428
Klas Mellbourn Avatar asked May 30 '13 13:05

Klas Mellbourn


2 Answers

If you have multiple remote repositories, and don't specify any remote repository name, origin will be used by default. If there is no remote repository named origin, then it will error out saying

fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.

Additionally: How can I change this default remote without making the local branch tracking?

You can rename that repository name to 'origin' to make it default.

Careful: this won't work if the current branch already has an upstream specified on a different remote.
From git help fetch:

When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch.

In this case, you can change the upstream branches to use origin by editing the remote fields for branches configured in .git/config.

like image 196
0xc0de Avatar answered Sep 22 '22 14:09

0xc0de


In your project folder, when you initialize git in the first step, .git folder is created.

Look into this folder for a file named config, it contains all the branch info. origin is used as the default.

  [remote "origin"]
      fetch = +refs/heads/*:refs/remotes/origin/*
      url = [email protected]:project.git

So the code is fetched from the url listed here.

like image 39
Bijendra Avatar answered Sep 18 '22 14:09

Bijendra