-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgitconfig_common
More file actions
107 lines (102 loc) · 3.55 KB
/
gitconfig_common
File metadata and controls
107 lines (102 loc) · 3.55 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
[core]
editor = nvim
[color]
ui = auto
diff = auto
status = auto
branch = auto
interactive = auto
[alias]
st = status
ci = commit
co = checkout
di = diff
dc = diff --cached
amend = commit --amend
aa = add --all :/
ff = merge --ff-only
pullff = pull --ff-only
noff = merge --no-ff
fa = fetch --all
pom = push origin main
b = branch
ds = diff --stat=160,120
dh1 = diff HEAD~1
head = !git l -1
h = !git head
hp = "! . ~/.githelpers && show_git_head"
r = !git l -30
ra = !git r --all
l = "! . ~/.githelpers && pretty_git_log"
la = !git l --all
pr = "! . ~/.githelpers && prune_and_delete_merged"
cleanlocal = "! . ~/.githelpers && clean_local"
current = !git rev-parse --abbrev-ref HEAD
some = !git checkout main && git pull --rebase && git remote prune origin && git cleanlocal
# Create a new worktree with a new branch and direnv setup
wt-new = "!f() { \
BRANCH_NAME=$1; \
WORKTREE_PATH=\"../$(basename $(pwd))-$BRANCH_NAME\"; \
git worktree add -b \"$BRANCH_NAME\" \"$WORKTREE_PATH\"; \
echo \"Worktree created at $WORKTREE_PATH\"; \
\
# Create a custom .envrc file for this worktree \
echo \"Creating direnv configuration...\"; \
if [ -f .envrc ]; then \
cp .envrc \"$WORKTREE_PATH/.envrc\"; \
else \
touch \"$WORKTREE_PATH/.envrc\"; \
fi; \
\
# Add worktree-specific environment variables \
echo \"\\n# Worktree-specific settings\" >> \"$WORKTREE_PATH/.envrc\"; \
echo \"export RAILS_WORKTREE_SUFFIX=\\\"${BRANCH_NAME//[-\\/]/_}\\\"\" >> \"$WORKTREE_PATH/.envrc\"; \
echo \"export PORT=\\\"$(( 3000 + $(echo $BRANCH_NAME | md5sum | tr -d -c 0-9 | cut -c 1-4) % 1000 ))\\\"\" >> \"$WORKTREE_PATH/.envrc\"; \
\
# Allow the new .envrc file \
(cd \"$WORKTREE_PATH\" && direnv allow); \
\
echo \"Setting up Rails environment...\"; \
(cd \"$WORKTREE_PATH\" && direnv exec . bundle install && direnv exec . bin/rails db:setup); \
\
echo \"\\nWorktree ready! To start the server:\\n cd $WORKTREE_PATH\\n bin/rails server # Will use PORT=$PORT from .envrc\"; \
}; f"
# Other aliases remain the same as before
wt-list = "worktree list"
wt-remove = "!f() { \
WORKTREE_PATH=\"../$(basename $(pwd))-$1\"; \
git worktree remove \"$WORKTREE_PATH\"; \
}; f"
wt-cleanup = "!f() { \
echo \"Cleaning up worktrees for merged branches...\"; \
MAIN_BRANCH=\"main\"; \
if git show-ref --verify --quiet refs/heads/master; then \
MAIN_BRANCH=\"master\"; \
fi; \
for worktree in $(git worktree list | grep -v \"$(git rev-parse --show-toplevel)\" | awk '{print $1}'); do \
BRANCH=$(cd $worktree && git symbolic-ref --short HEAD 2>/dev/null); \
if [ -n \"$BRANCH\" ] && [ \"$BRANCH\" != \"$MAIN_BRANCH\" ]; then \
if git merge-base --is-ancestor $BRANCH $MAIN_BRANCH; then \
echo \"Removing worktree for merged branch: $BRANCH at $worktree\"; \
git worktree remove --force \"$worktree\"; \
git branch -d \"$BRANCH\"; \
fi; \
fi; \
done; \
git worktree prune; \
echo \"Cleanup complete.\"; \
}; f"
wt-code = "!f() { \
WORKTREE_PATH=\"../$(basename $(pwd))-$1\"; \
if [ -d \"$WORKTREE_PATH\" ]; then \
code \"$WORKTREE_PATH\"; \
else \
echo \"Worktree $WORKTREE_PATH does not exist\"; \
fi; \
}; f"
[merge]
tool = vimdiff
[push]
default = current
[commit]
template = ~/.gitmessage