git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Trying to Update All Heads of a Repository

From
Linus Torvalds <torvalds@osdl.org>
Date
Nov 4, 2005, 01:04 UTC
Message-ID
<Pine.LNX.4.64.0511031655350.27915@g5.osdl.org>
In-Reply-To
<E1EXpN9-00034x-7g@jdl.com>
On Thu, 3 Nov 2005, Jon Loeliger wrote:
> 
> I don't know how to say "Grab all the updates for
> all the heads for which I have heads in my .git/refs".

Well, you can't per se - there's no guarantee that the heads on the other side match, and in fact usually they won't (at the very minimum, the remote "master" tends to be the local "origin", although if you never do any development at _all_, you can make even that match).

I sent out a patch some time ago that added "--all" and "--tags", but only the "--tags" part was accepted. Arguably for good reasons.

But "git fetch" will take a list of heads. So you can do
	git fetch repo master:origin pu todo

and it will update the three local heads (origin, pu and todo) from the remote heads master, pu and todo respectively).

IF you have a 100% match between heads names locally and remotely, you could also do something like

	git fetch repo $(cd .git/refs ; echo heads/*)
which is pretty cheesy, but should work ;)

As to your experiences with "git pull" - it should work fine too, but you really do need to make sure that the branch you are in always matches the branch you're pulling. Otherwise you'll be doing a merge between two different branches - which is a valid operation, but not what you're trying to achieve here.

As we saw earlier, the way to undo an unsuccessful "git pull" is to do a "git reset --hard". Undoing a _successful_ git pull is actually slightly harder in the general case (it's really undoing a series of commit), but if you do it right after the pull, you can do

	git reset --hard ORIG_HEAD
because "git pull" will save the original head before pulling.
			Linus
Previous: Jon LoeligerNext: Junio C Hamano
Message 2 of 6 in “Trying to Update All Heads of a Repository”
  1. Jon LoeligerNov 4, 2005
  2. Linus TorvaldsNov 4, 2005
  3. Junio C HamanoNov 4, 2005
  4. Daniel BarkalowNov 4, 2005
  5. Junio C HamanoNov 5, 2005
  6. Set up remotes/origin to track all remote branches.Junio C Hamano, Nov 6, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.