Created
May 8, 2017 20:51
-
-
Save phellipeandrade/6f20db3d29a847f66fee31f3883e1288 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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