forked from johnib/ado-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_branch.sh
More file actions
executable file
·37 lines (29 loc) · 879 Bytes
/
create_branch.sh
File metadata and controls
executable file
·37 lines (29 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# Check if a branch name is provided
if [ -z "$1" ]; then
echo "Usage: $0 <branch_name>"
exit 1
fi
branch_name="$1"
# Fetch latest changes from main
git fetch origin main
# Prune remote-tracking branches that no longer exist on the remote
git remote prune origin
# Check if the branch already exists locally
if git rev-parse --verify --quiet "$branch_name" > /dev/null 2>&1; then
echo "Error: Branch '$branch_name' already exists locally."
exit 1
fi
# Check if branch exists on remote
if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then
echo "Error: Branch '$branch_name' already exists on remote."
exit 1
fi
# Create the new branch
git checkout -b "$branch_name" origin/main
if [ $? -eq 0 ]; then
echo "Branch '$branch_name' created successfully."
else
echo "Failed to create branch '$branch_name'."
exit 1
fi