Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phellipeandrade/6f20db3d29a847f66fee31f3883e1288 to your computer and use it in GitHub Desktop.
Save phellipeandrade/6f20db3d29a847f66fee31f3883e1288 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Fetch the latest branches
git fetch
# Get the repository path
repoPath=$(git config --get remote.origin.url)
dir=$(pwd)
# Loop through each branch
for branches in $(git for-each-ref --format='%(refname)' refs/remotes/)
do
# Remove redundant string from branch name
myBranch=${branches/refs\/remotes\/origin\//}
# Check if we are using 'HEAD' branch
if [ "$myBranch" == "HEAD" ]
then
continue
fi
# Check if the branch has already been checked out
if [ -e "$dir"/git/branches/"$myBranch" ]
then
# Switch to the branch directoryls
cd "$dir"/git/branches/"$myBranch" || exit
echo "$myBranch" ' - Checking for updates.'
# Pull latest code
status=$(git pull)
# Check if there are any changes
if [ "$status" == "Already up-to-date." ]
then
echo "$myBranch" ' - Already up-to-date.'
continue
else
echo "$myBranch" ' - Updating node packages'
npm install
continue
fi
else
# Switch to branches directory
cd "$dir"/git/branches/ || exit
# Clone repository to branch named directory
git clone "$repoPath" "$myBranch"
# Switch to specific branch directory
cd "$dir"/git/branches/"$myBranch" || exit
npm install
# Switch to the branch
git checkout "$myBranch"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment