-
Notifications
You must be signed in to change notification settings - Fork 0
/
faster-git.sh
61 lines (51 loc) · 1.5 KB
/
faster-git.sh
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
killport() {
lsof -ti:$1 | xargs kill
}
alias gs="git status"
alias gbp="git push origin \$(git symbolic-ref --short HEAD) -u --no-verify"
alias gfp="git add -A && git recommit && git push origin \$(git symbolic-ref --short HEAD) -u --no-verify -f"
alias grc="git add -A && GIT_EDITOR=true git rebase --continue"
alias gtree="git log --graph --full-history --all --color --pretty=format:\"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s\""
git config --global alias.recommit 'commit --amend --no-edit'
gb() {
if [ -z "$1" ]; then
git branch;
else
git checkout -b $1;
fi
}
gco() {
BRANCHES=`git for-each-ref --format="%(refname:short)" refs/heads | grep $1`
BRANCHES_COUNT=`git for-each-ref --format="%(refname:short)" refs/heads | grep $1 | wc -l`
if [ $BRANCHES_COUNT -gt 1 ]; then
echo "Too many matches:";
for branch in $BRANCHES; do echo " $branch"; done
return 0
elif [ $BRANCHES_COUNT -eq 1 ]; then
git checkout $BRANCHES
else
echo "Not found"
fi
}
git_branch() {
git symbolic-ref --short HEAD 2> /dev/null
}
git_list_branches() {
git for-each-ref refs/heads --format='%(refname)' | cut -d/ -f3-
}
ga() {
PATTERN=$1
CHANGES=$(git ls-files -m | grep $PATTERN -)
for file in $CHANGES; do
echo "+ $file";
git add $file
done
}
grm() {
masterBranch='master'
hasMaster=`git for-each-ref --format="%(refname:short)" refs/heads | grep master | wc -l`
if [ $hasMaster -eq 0 ]; then
masterBranch='main'
fi
git fetch && git rebase origin/$masterBranch
}