I'm trying to get from my git repo all branches (git branches -a
) that matches regex (grep xxx
).
Normally in command line I write this:
git branch -a | grep xxx
So I'm trying to do the same in .sh file:
- get all branches that matches regex
- split it into array
- get first branch
Below is my code:
#!/bin/bash
branches=( $(git branch -a | grep $1) )
echo branches : $branches
echo branch : ${branches[0]}
Sadly it somehow add all files in my current folder.
This is the output:
$> checkout.sh 2887
branches : ant
branch : ant
If I change branches=( $(git branch -a | grep $1) )
to branches=$(git branch -a | grep $1)
I got all files in my dir and branches at the end