Skip to content

Commit ffd0e29

Browse files
authored
Merge pull request #131 from thaim/install-git-custom-script
Add git custom command: git-switch-default
2 parents 535b1f1 + f107942 commit ffd0e29

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

roles/git/files/git-switch-default

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# git-switch-default - Switch to the remote default branch
3+
4+
# Get default branch name (from local cache without remote access)
5+
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
6+
7+
# Exit if symbolic reference is not found
8+
if [ -z "$default_branch" ]; then
9+
echo "Error: refs/remotes/origin/HEAD does not exist."
10+
exit 1
11+
fi
12+
13+
git switch "$default_branch"

roles/git/tasks/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@
4949

5050
- name: Setup git-completion
5151
ansible.builtin.include_tasks: setup_git_completion.yml
52+
53+
54+
- name: Install custom commands script
55+
ansible.builtin.copy:
56+
src: git-switch-default
57+
dest: /usr/local/bin/git-switch-default
58+
mode: '0755'

0 commit comments

Comments
 (0)