Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: What's the difference between fetching from named remote and fetching from a URL?

Tags:

git

fetch

Suppose I clone a git repository from the path /path/to/repo. The original repository will be a remote called "origin". I can fetch objects from the origin with the command git fetch origin. This will retrieve all the objects from the remote "origin", including any branches made.

What's curious is that if I explicitly fetch from that same repository with the command git fetch /path/to/repo, I appear to retrieve all of the commit objects but not any of the branches.

Why is that? Am I not doing exactly the same thing in both cases? How can Git's behavior be so different?

like image 883
Jocko Homo Avatar asked Dec 29 '12 20:12

Jocko Homo


People also ask

What is the difference between GIT fetch origin and fetch?

$ git fetch origin. git fetch really only downloads new data from a remote repository - but it doesn't integrate any of this new data into your working files. Fetch is great for getting a fresh view on all the things that happened in a remote repository.

How do I fetch a specific branch in Git?

The simplest way to use the git fetch command is to fetch a remote repository: Note: The git fetch command without the remote name retrieves data from an origin. If the remote has a different name, state the name in the command. The output shows the command fetched all the contents from the remote repository, including branches and tags.

How do I pull changes from a remote repository in Git?

After opening the Fuzzy Finder, you can simply type fetch to begin a Git fetch, or pull to initiate a Git pull. Auto-Fetch Changes with GitKraken GitKraken includes a convenient feature that allows you to automatically fetch changes from a remote repository based on an interval you define.

How do I list all the tags fetched from a repository?

To list all the fetched tags, run: Use the git checkout command to make the contents locally available to a new branch or use git merge to synchronize local repository information. To fetch a specific branch from a repository, run this command: For example, to fetch a branch named test from the origin, run:


1 Answers

Named remote use their configuration where they setup a refspec schema when this remote is fetched:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url   = /path/to/repo

So, these two format are equivalent:

git fetch origin
git fetch /path/to/repo +refs/heads/*:refs/remotes/origin/*

Basically: git fetch <path> <source>:<destination>. And the destination is important here because it's where the remote HEAD and branches pointer are stored.

By doing git fetch /path/to/repo, you don't set any refspec. As so, it only fetches the commits, not the objects because git hasn't been instructed to get and store them.

There may be some details or naming convention incorrect here, feel free to edit. But the global idea should be correct

like image 101
Simon Boudrias Avatar answered Sep 20 '22 21:09

Simon Boudrias