1

i'm working with jenkins/git and i want to clean my directory (/var/www/branches/) from old git branches this branches are represented as folders in a different directory ( a part from my git repository), what i do is that i retrieve current working branches put them in a file using the command :

listBranchRemote=$(git --git-dir=$gitDirectory/.git branch -qr |cut -d'/' -f 2,3 | tee -a branch.txt )

the branch.txt represents the only folders that should be kept in /var/www/branches/ directory. How to delete folders not in my file that i created.

AILY
  • 345
  • 2
  • 3
  • 16

1 Answers1

0

You can apply a similar process than "How to iterate through all git branches using bash script", except you would need to:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • iterating over local branches needs to be done in my git repository, but as i said i only have representation of these branches as folder in another directory a part from my local git repository – AILY Jul 10 '18 at 09:29
  • @AILY Branches are not directory in Git. Can you edit your question to illustrate what those "branches" are in your own workspace? – VonC Jul 10 '18 at 09:31
  • @AILY If you had cloned/checkout branches in their own folder in `/var/www/branches/`directly, you can delete those subfolder: the `then ... delete` part of my answer becomes `rm -Rf /var/www/branches/abranch_name`. – VonC Jul 10 '18 at 11:32