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

A simple script to do the reverse of git-push

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 8, 2005, 21:25 UTC
Message-ID
<Pine.LNX.4.63.0508082318400.2911@wgmdd8.biozentrum.uni-wuerzburg.de>
Hi list,

I mentioned in another mail that I needed the opposite of git-push, namely getting all heads, and if they are strict parents of the local refs, just update them.

Well, Junio pointed out that it's easy using the available tools, and he was right. The result is attached (and tested...).

This script makes it easy to work with a central repository, multiple heads and users, in a CVS style: to start your day, you call the attached script, and after you have committed something, you can do a push on the repository. Sometimes, the push fails, then you have to pull that branch in order to merge it before trying a push again.

BTW, if you are lazy, like me, you just pull from Junio once in a while and do a "make test". Turns out there is a missing dependency though:

peek-remote.o: cache.h

which in my case lead to a git-peek-remote program which was unable to peek any ref.

Ciao, Dscho

#!/bin/sh
. git-sh-setup-script || die "Not a git archive"

. git-parse-remote "$@" repo="$_remote_repo"

git-ls-remote-script --heads "$repo" | while read sha1 refname; do
	shortname=$(basename $refname)
	if [ -e $GIT_DIR/$refname ]; then
		if [ $sha1 = $(cat $GIT_DIR/$refname) ]; then
			echo $shortname up to date. 1>&2
			continue
		fi
	fi
	git-cat-file commit $sha1 >/dev/null 2>&1 ||
	git-fetch-script $repo $shortname
	if [ ! -e $GIT_DIR/$refname ]; then
		echo Got new head $shortname 1>&2
		echo $sha1 > $GIT_DIR/$refname
	else
		origsha1=$(cat $GIT_DIR/$refname)
		if [ -z "$(git-rev-list $origsha1 ^$sha1)" ]; then
			echo Updated head $shortname 1>&2
			echo $sha1 > $GIT_DIR/$refname
		else
			saveref=$GIT_DIR/FETCH_HEAD_$shortname
			echo Error: $shortname not a child of remote head 1>&2
			echo "	Saved remote head to $saveref" 1>&2
			echo $sha1 > $saveref
		fi
	fi
done
Next: Junio C Hamano
Message 1 of 4 in “A simple script to do the reverse of git-push”
  1. Johannes SchindelinAug 8, 2005
  2. Junio C HamanoAug 8, 2005
  3. Johannes SchindelinAug 8, 2005
  4. Petr BaudisAug 11, 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.