]> gitweb.fluxo.info Git - utils-git.git/commitdiff
Feat: adds git-clone-or-pull
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 19 Jun 2024 12:07:28 +0000 (09:07 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 19 Jun 2024 12:07:28 +0000 (09:07 -0300)
git-clone-or-pull [new file with mode: 0755]

diff --git a/git-clone-or-pull b/git-clone-or-pull
new file mode 100755 (executable)
index 0000000..f2575c2
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# Handy single command to clone or pull a repository
+#
+
+# Parameters
+BASENAME="`basename $0`"
+ORIGIN="$1"
+DEST="$2"
+
+# Check
+if [ -z "$DEST" ]; then
+  echo "usage: $BASENAME <origin> <dest>"
+  exit 1
+fi
+
+# Dispatch
+if [ ! -e "$DEST" ]; then
+  echo "Cloning $ORIGIN into $DEST..."
+  git clone $ORIGIN $DEST
+else
+  echo "Updating $DEST..."
+  git -C $DEST pull
+
+  # Alternate approach, that restore any existing changes
+  #(
+  #  cd $DEST &> /dev/null
+  #  git restore .
+  #  git pull
+  #)
+fi
+
+# Exit
+exit $?