3

I'm working locally and pushing the contents to repository. My client need a shell script to pull the latest code from bitbucket repository.

It's possible to run git pull from the staging server. how can i create a shell script for the same.

I have seen examples in various answers but not a correct solution to my question.I don't know how to work it out.

I'm not familiar with shell script. It would be helpful if somebody can help me to do the task.

Hugo y
  • 1,421
  • 10
  • 20
Geethu
  • 348
  • 6
  • 24

1 Answers1

1

Your script will need to create a local repo in a pre-determined path, and then pull

#!/bin/bash
if [ ! -e /a/path/for/local/repo ]; then
    mkdir -p /a/path/for/local/repo
fi
cd /a/path/to/local/repo
if [ ! -e .git ]; then
    git init .
fi
origin=$(git config --get remote.origin.url)
if [ "${origin}" == "" ]; then
    git remote add origin https://bitbucket.org/<account>/<repo>.git
fi
git pull origin master

This assumes the client has Git already installed and in its $PATH.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @Shalom What version of Git are you using? (https://stackoverflow.com/a/32991851/6309) – VonC Jan 30 '18 at 05:38
  • 1.9.1 is the git version – Geethu Jan 30 '18 at 05:42
  • @Shalom 1.9.1 is very old. As I mention in https://stackoverflow.com/a/32991851/6309, this command is for Git 2.7+. Do upgrade first. – VonC Jan 30 '18 at 05:43
  • @Shalom I have edited the answer to use a command that will work with Git 1.9.1, if you cannot upgrade – VonC Jan 30 '18 at 05:44