Home > Blockchain >  Take all files and folders from all branches in Git
Take all files and folders from all branches in Git

Time:10-22

I would like to create a script for Git that takes all folders from all branches in Git and put it into the master branch. My starting point is:

#!/usr/bin/env bash

for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do
    git log --oneline "$branch"
done

Please help! Thank you!

CodePudding user response:

Here is my solution:

#!/usr/bin/env bash

# CHANGE REPOSITORY LINK!!!
git clone https://github.com/{owner}/docs_repo_for_script_test
mkdir content
# CHANGE REPOSITORY NAME AT THE LINE BELOW!!!
cd docs_repo_for_script_test

for BRANCH in $(git branch -a | grep remotes/origin | grep -v HEAD) ;
do
    FOLDER="../content/$(cut -d'/' -f3 <<<"$BRANCH")"
    echo branch: !$BRANCH!
    echo folder: !$FOLDER!
    git checkout $BRANCH
    mkdir $FOLDER
    cp -r * $FOLDER
done
  •  Tags:  
  • git
  • Related