fixing checkout branches scripts
This commit is contained in:
parent
9dbd2485cd
commit
10c80bb983
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Prune worktree references to remove any missing worktrees
|
||||
git worktree prune
|
||||
|
||||
# List remote branches that start with 'origin/preprod'
|
||||
for branch in $(git branch -r | grep 'origin/preprod' | sed 's|origin/||'); do
|
||||
# Extract the directory name without 'preprod_' prefix
|
||||
dir_name=$(echo $branch | sed 's|^preprod_||')
|
||||
|
||||
# Create the directory if it doesn't exist
|
||||
mkdir -p "../${dir_name}"
|
||||
|
||||
# Add the worktree
|
||||
git worktree add "../${dir_name}" "origin/${branch}" || {
|
||||
echo "Failed to add worktree for branch ${branch}"
|
||||
continue
|
||||
}
|
||||
|
||||
# Change to the new worktree directory and check out the branch
|
||||
cd "../${dir_name}"
|
||||
git checkout "${branch}" || {
|
||||
echo "Failed to checkout branch ${branch} in directory ${dir_name}"
|
||||
continue
|
||||
}
|
||||
cd - > /preprod/null
|
||||
done
|
||||
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# List all branches that start with "dev" and check out each branch into a separate directory
|
||||
for branch in $(git branch -r | grep "origin/dev" | sed "s|origin/||"); do
|
||||
# Create a new directory for each branch
|
||||
mkdir "../${branch}"
|
||||
# Check out the branch into the newly created directory
|
||||
git worktree add "../${branch}" $branch
|
||||
done
|
||||
|
||||
# List all branches that start with "preprod" and check out each branch into a separate directory
|
||||
for branch in $(git branch -r | grep "origin/preprod" | sed "s|origin/||"); do
|
||||
# Create a new directory for each branch
|
||||
mkdir "../${branch}"
|
||||
# Check out the branch into the newly created directory
|
||||
git worktree add "../${branch}" $branch
|
||||
done
|
||||
|
||||
# List all branches that start with "master" and check out each branch into a separate directory
|
||||
for branch in $(git branch -r | grep 'origin/master' | grep -vE 'origin/(HEAD|master$)' | sed 's|origin/||'); do
|
||||
# Create a new directory for each branch
|
||||
mkdir "../${branch}"
|
||||
# Check out the branch into the newly created directory
|
||||
git worktree add "../${branch}" $branch
|
||||
done
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Prune worktree references to remove any missing worktrees
|
||||
git worktree prune
|
||||
|
||||
# Function to add worktree and check out branch
|
||||
add_worktree_and_checkout() {
|
||||
local branch=$1
|
||||
|
||||
# Create the directory if it doesn't exist
|
||||
mkdir -p "../${branch}"
|
||||
|
||||
# Add the worktree
|
||||
git worktree add "../${branch}" "origin/${branch}" || {
|
||||
echo "Failed to add worktree for branch ${branch}"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Change to the new worktree directory and check out the branch
|
||||
cd "../${branch}"
|
||||
git checkout "${branch}" || {
|
||||
echo "Failed to checkout branch ${branch} in directory ${branch}"
|
||||
return 1
|
||||
}
|
||||
cd - > /dev/null
|
||||
}
|
||||
|
||||
# List remote branches that start with 'origin/dev'
|
||||
for branch in $(git branch -r | grep 'origin/dev' | sed 's|origin/||'); do
|
||||
add_worktree_and_checkout "${branch}"
|
||||
done
|
||||
|
||||
# List all branches that start with "preprod" and check out each branch into a separate directory
|
||||
for branch in $(git branch -r | grep 'origin/preprod' | sed 's|origin/||'); do
|
||||
add_worktree_and_checkout "${branch}"
|
||||
done
|
||||
|
||||
# List all branches that start with "master" and check out each branch into a separate directory
|
||||
for branch in $(git branch -r | grep 'origin/master' | grep -vE 'origin/(HEAD|master$)' | sed 's|origin/||'); do
|
||||
add_worktree_and_checkout "${branch}"
|
||||
done
|
||||
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# List all branches that start with "dev" and check out each branch into a separate directory
|
||||
for branch in $(git branch -r | grep 'origin/dev' | sed 's|origin/||'); do
|
||||
# Extract the directory name without 'dev_' prefix
|
||||
dir_name=$(echo $branch | sed 's|^dev_||')
|
||||
mkdir "../${dir_name}"
|
||||
git worktree add "../${dir_name}" $branch
|
||||
done
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Prune worktree references to remove any missing worktrees
|
||||
git worktree prune
|
||||
|
||||
# List remote branches that start with 'origin/dev'
|
||||
for branch in $(git branch -r | grep 'origin/dev' | sed 's|origin/||'); do
|
||||
# Extract the directory name without 'dev_' prefix
|
||||
dir_name=$(echo $branch | sed 's|^dev_||')
|
||||
|
||||
# Create the directory if it doesn't exist
|
||||
mkdir -p "../${dir_name}"
|
||||
|
||||
# Add the worktree
|
||||
git worktree add "../${dir_name}" "origin/${branch}" || {
|
||||
echo "Failed to add worktree for branch ${branch}"
|
||||
continue
|
||||
}
|
||||
|
||||
# Change to the new worktree directory and check out the branch
|
||||
cd "../${dir_name}"
|
||||
git checkout "${branch}" || {
|
||||
echo "Failed to checkout branch ${branch} in directory ${dir_name}"
|
||||
continue
|
||||
}
|
||||
cd - > /dev/null
|
||||
done
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Prune worktree references to remove any missing worktrees
|
||||
git worktree prune
|
||||
|
||||
# List remote branches that start with 'origin/preprod'
|
||||
for branch in $(git branch -r | grep 'origin/preprod' | sed 's|origin/||'); do
|
||||
# Extract the directory name without 'preprod_' prefix
|
||||
dir_name=$(echo $branch | sed 's|^preprod_||')
|
||||
|
||||
# Create the directory if it doesn't exist
|
||||
mkdir -p "../${dir_name}"
|
||||
|
||||
# Add the worktree
|
||||
git worktree add "../${dir_name}" "origin/${branch}" || {
|
||||
echo "Failed to add worktree for branch ${branch}"
|
||||
continue
|
||||
}
|
||||
|
||||
# Change to the new worktree directory and check out the branch
|
||||
cd "../${dir_name}"
|
||||
git checkout "${branch}" || {
|
||||
echo "Failed to checkout branch ${branch} in directory ${dir_name}"
|
||||
continue
|
||||
}
|
||||
cd - > /preprod/null
|
||||
done
|
||||
|
||||
Loading…
Reference in New Issue