-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc-git
More file actions
156 lines (140 loc) · 4.08 KB
/
bashrc-git
File metadata and controls
156 lines (140 loc) · 4.08 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
COLOR_RESET="\[\033[0;39;49m\]"
COLOR_BRANCH="\[\033[0;1;32;44m\]"
COLOR_REPO="\[\033[0;1;33;44m\]"
COLOR_WORKDIR="\[\033[0;1;33;42m\]"
MOD_GLYPH="*"
STATE_GLYPH="|"
PS1_GLYPH="\$"
# shamelessly ripped off from http://github.com/rtomayko/git-sh/tree/master
# ... and Ubuntu's __git_ps1() in /etc/bash_completion.d/git
_git_prompt_color() {
local g r b rel loc mod
g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -z $g ]; then
export BASH_GIT_BRANCH=""
PS1="\u@\h:\w$PS1_GLYPH "
return
fi
if [ -d "$g/../.dotest" ]
then
if test -f "$g/../.dotest/rebasing"
then
r="${STATE_GLYPH}REBASE"
elif test -f "$g/../.dotest/applying"
then
r="${STATE_GLYPH}AM"
else
r="${STATE_GLYPH}AM/REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
elif [ -f "$g/.dotest-merge/interactive" ]
then
r="${STATE_GLYPH}REBASE-i"
b="$(cat "$g/.dotest-merge/head-name")"
elif [ -d "$g/.dotest-merge" ]
then
r="${STATE_GLYPH}REBASE-m"
b="$(cat "$g/.dotest-merge/head-name")"
elif [ -f "$g/MERGE_HEAD" ]
then
r="${STATE_GLYPH}MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f "$g/BISECT_LOG" ]
then
r="${STATE_GLYPH}BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
b="${b##refs/heads/}" # make it a pretty name
export BASH_GIT_BRANCH="$b"
mod=`git ls-files --modified --deleted --others --exclude-standard 2>/dev/null | head -1`
if [ ! -z "$mod" ]; then
r="${MOD_GLYPH}$r"
fi
rel=$(git rev-parse --show-prefix 2>/dev/null)
rel="${rel%/}"
loc="${PWD%/$rel}"
PS1="\u@\h:${COLOR_BRANCH}${b}${r}${COLOR_RESET}!${COLOR_REPO}${loc/*\/}${COLOR_RESET}${COLOR_WORKDIR}${rel:+/$rel}${COLOR_RESET}${PS1_GLYPH} "
}
###############################################################################
# Use the fancy Git prompt
PROMPT_COMMAND=_git_prompt_color
###############################################################################
whatgitbranch() {
local branch
branch="$(git symbolic-ref HEAD 2>/dev/null)"
branch="${branch##refs/heads/}"
echo "$branch"
}
gunpushed() {
local branch
branch=$(whatgitbranch)
set -x
git log --pretty=oneline "origin/$branch.."
set +x
}
gunpulled() {
local branch
branch=$(whatgitbranch)
set -x
git log --pretty=oneline "..origin/$branch"
set +x
}
makebranch() {
local branch gitdir
branch=$1
gitdir=$(git rev-parse --git-dir 2>/dev/null)
if [ -e "$gitdir/refs/heads/$branch" ]; then
# ERROR: branch exists locally
echo "branch '$branch' exists locally; can't create new branch"
else
git fetch
if [ -e "$gitdir/refs/remotes/origin/$branch" ]; then
# ERROR: branch exists remotely
echo "branch '$branch' exists remotely; can't create new branch"
else
set -x
git branch $branch
git push --set-upstream origin $branch
git checkout $branch
set +x
fi
fi
}
gpu() {
local branch gitdir
branch="$(whatgitbranch)"
set -x
git push origin $branch
set +x
}
setbranch() {
local branch gitdir
branch=$1
gitdir=$(git rev-parse --git-dir 2>/dev/null)
if [ -e "$gitdir/refs/heads/$branch" ]; then
git checkout $branch
else
git fetch
if [ -e "$gitdir/refs/remotes/origin/$branch" ]; then
git checkout --track -b $branch origin/$branch
else
echo "branch '$branch' doesn't exist; did you want to 'makebranch'?"
fi
fi
}
alias gst='git status'
alias gd='git diff'
alias gdc='git diff --cached'
alias glol='git log --pretty=oneline'
alias glop='git log -p -1'
alias gci='git commit --verbose'
alias gup='git pull --rebase'
alias gbr='git branch -vv'