Linux interactions: Cloning, Pulling, and Pushing to a Repository

Clone a repository

%%script bash


cat <<EOF > /tmp/variables.sh
export project_dir=$HOME/tester
export project=\$project_dir/tester
export project_repo="https://github.com/MaryamAbdul-Aziz/tester.git"
EOF

%%script bash 
# ^ used to start every bash script

# extract variables
source /tmp/variables.sh

cd ~ # begin in home directory

echo "Checking for existence of project directory and project"


if [ ! -d "$project_dir" ] # if the directory does not exist, then...
then 
    echo "Directory $project_dir does not exist"
    echo "Making directory $project_dir"
    mkdir -p "$project_dir"
fi

echo "Directory $project_dir exists." 

# git clone a project from repo if it does not exist

echo ""

if [ ! -d $project_repo ] # if project does not exist, then...
then
    echo "Directory $project does not exist"
    echo "Cloning $project_repo"
    cd "$project_dir"
    git clone "$project_repo"
    cd ~
fi

echo "Directory $project_dir exists." 

Checking for existence of project directory and project
Directory /Users/maryamabdul-aziz/tester does not exist
Making directory /Users/maryamabdul-aziz/tester
Directory /Users/maryamabdul-aziz/tester exists.

Directory /Users/maryamabdul-aziz/tester/tester does not exist
Cloning https://github.com/MaryamAbdul-Aziz/tester.git


Cloning into 'tester'...


Directory /Users/maryamabdul-aziz/tester exists.

Viewing working directory and list of all files within project

Using ls and pwd

%%script bash
# ^ used to start every bash script

echo "Navigating to project and printing working directory"
echo ""
cd $project
echo "Working directory:"
pwd

echo "Listing all files within directory"
cd $project
echo ""
echo "Files:"
ls
Navigating to project and printing working directory

Working directory:
/Users/maryamabdul-aziz
Listing all files within directory

Files:
Applications
Desktop
Documents
Downloads
Dropbox
Library
Movies
Music
Pictures
Public
gems
src
tester
vscode
%%script bash
# ^ used to start every bash script

echo "Navigating to project and printing working directory"
echo ""
cd $project
echo""
echo "Working directory:"
pwd

echo "Listing all files within directory"
echo ""
cd $project
echo "Files:"
ls
Navigating to project and printing working directory


Working directory:
/Users/maryamabdul-aziz
Listing all files within directory

Files:
Applications
Desktop
Documents
Downloads
Dropbox
Library
Movies
Music
Pictures
Public
gems
src
tester
vscode