Last active
February 1, 2024 12:37
-
-
Save schtibe/f24cb24c3b47b2c5e532799cc2e42c8b to your computer and use it in GitHub Desktop.
Git switch branch helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
git fetch > /dev/null | |
# Get the list of branches from "git branch -a" using fzf for interactive selection | |
selected_branch=$(git branch -a | grep -v HEAD | sed 's/^[[:space:]]*//' | fzf --ansi --prompt="Select a branch (Use arrow keys): ") | |
if [ -n "$selected_branch" ]; then | |
if [ "$selected_branch" == "Exit" ]; then | |
echo "Exiting..." | |
else | |
echo "You selected branch: $selected_branch" | |
cleaned_branch_name=${selected_branch/remotes\//} | |
cleaned_branch_name=${cleaned_branch_name/origin\//} | |
echo "Checking out $cleaned_branch_name" | |
git switch $cleaned_branch_name | |
fi | |
else | |
echo "No branch selected. Exiting..." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment