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

[PATCH] Add "git push"

From
Matthias Urlichs <smurf@smurf.noris.de>
Date
Apr 21, 2005, 12:43 UTC
Message-ID
<20050421124333.AB2CE7F887@smurf.noris.de>

This patch adds the ability to "git push", as the obvious converse of "git pull".

Signed-Off-By: Matthias Urlichs <smurf@smurf.noris.de>
Index: git
===================================================================
--- 42a073eb6b5bb397a3e8768a032463a7fa02e6b9/git  (mode:100755 sha1:557122dfb05580e4af2c55767f3d6f92b9110edd)
+++ 265515f9c4f089b1b61e9d2312c4b3babe189618/git  (mode:100644 sha1:c32ee037c4dd68f8fa6723cb115644d46810bc89)
@@ -42,6 +42,7 @@
 	merge		[-c] [-b BASE_ID] FROM_ID
 	patch		[COMMIT_ID]
 	pull		[RNAME]
+	push		[RNAME]
 	rm		FILE...
 	seek		[COMMIT_ID]
 	status
@@ -86,6 +87,7 @@
 "lsremote")   gitlsremote.sh "$@";;
 "merge")      gitmerge.sh "$@";;
 "pull")       gitpull.sh "$@";;
+"push")       gitpush.sh "$@";;
 "patch")      gitpatch.sh "$@";;
 "rm")         gitrm.sh "$@";;
 "seek")       gitseek.sh "$@";;
--- /dev/null  (tree:42a073eb6b5bb397a3e8768a032463a7fa02e6b9)
+++ 265515f9c4f089b1b61e9d2312c4b3babe189618/gitpush.sh  (mode:100644 sha1:0a658141991c602ca327edb9ab982d7660d7c665)
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# Pushes changes from the local GIT repository to "remote".
+# Copyright (c) Matthias Urlichs, 2005
+#
+# Takes the remote's name.
+
+name=$1
+
+die () {
+	echo gitpush.sh: $@ >&2
+	exit 1
+}
+
+
+[ "$name" ] || name=$(cat .git/tracking 2>/dev/null)
+[ "$name" ] || die "where to push to?"
+uri=$(grep $(echo -e "^$name\t" | sed 's/\./\\./g') .git/remotes | cut -f 2)
+[ "$uri" ] || die "unknown remote"
+
+
+tracking=
+[ -s .git/tracking ] && tracking=$(cat .git/tracking)
+
+orig_head=
+if [ "$tracking" = "$name" ]; then
+	[ -s .git/HEAD.tracked ] && orig_head=$(cat .git/HEAD.tracked)
+else
+	[ -s ".git/heads/$name" ] && orig_head=$(cat ".git/heads/$name")
+fi
+
+rsync $RSYNC_FLAGS -Lr "$uri/HEAD" ".git/HEAD_$name"
+$id=$(cat ".git/HEAD_$name")
+rm .git/HEAD_$name
+
+if [ -z "$id" ] ; then
+	echo "The remote system doesn't have a HEAD file: Doing an initial upload." >&2
+	echo "." >&2
+elif [ "$(cat-file -t "$id")" != "commit" ]; then
+	echo "The remote system has stuff we don't have: pull first!" >&2
+	echo "	Commit ID: $id" >&2
+	exit 1
+fi
+
+# We already saw the MOTD, thank you very much.
+rsync $RSYNC_FLAGS --ignore-existing --whole-file \
+	-v -r ".git/objects" "$uri" | grep -v '^MOTD:'
+
+# FIXME: Warn about conflicting tag names?
+rsync $RSYNC_FLAGS --ignore-existing \
+	-v -r ".git/tags" "$uri" 2>/dev/null | grep -v '^MOTD:'
+
+# Finally, update the remote HEAD
+rsync $RSYNC_FLAGS -Lr ".git/HEAD" "$uri/HEAD" \
+	2>/dev/null | grep -v '^MOTD:'
+
+echo "Now up to date."
+exit
+
Next: Petr Baudis
Message 1 of 2 in “Add "git push"”
  1. Add "git push"Matthias Urlichs, Apr 21, 2005
  2. Petr BaudisApr 21, 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.