-# Update origin.
-mkdir -p "$D/.git/remotes/" &&
-rm -f "$D/.git/remotes/origin" &&
-echo >"$D/.git/remotes/origin" \
-"URL: $repo
-Pull: master:origin"
+cd "$D" || exit
+
+if test -f "$GIT_DIR/HEAD"
+then
+ head_points_at=`git-symbolic-ref HEAD`
+ case "$head_points_at" in
+ refs/heads/*)
+ head_points_at=`expr "$head_points_at" : 'refs/heads/\(.*\)'`
+ mkdir -p "$GIT_DIR/remotes" &&
+ echo >"$GIT_DIR/remotes/origin" \
+ "URL: $repo
+Pull: $head_points_at:$origin" &&
+ git-update-ref "refs/heads/$origin" $(git-rev-parse HEAD) &&
+ (cd "$GIT_DIR" && find "refs/heads" -type f -print) |
+ while read ref
+ do
+ head=`expr "$ref" : 'refs/heads/\(.*\)'` &&
+ test "$head_points_at" = "$head" ||
+ test "$origin" = "$head" ||
+ echo "Pull: ${head}:${head}"
+ done >>"$GIT_DIR/remotes/origin"
+ esac
+
+ case "$no_checkout" in
+ '')
+ git checkout
+ esac
+fi