-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-linux
More file actions
176 lines (166 loc) · 6.61 KB
/
Copy pathgit-linux
File metadata and controls
176 lines (166 loc) · 6.61 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Add this after the standard Debian-style bash stuff
# Regular aliases
alias ffs='sudo "$BASH" -c "$(history -p !!)"'
alias bi='brew install'
alias br='brew uninstall'
alias bu='brew update'
# Color fix for home monitor: see: https://lucascosti.com/blog/2016/08/monitor-colour-problems-over-hdmi/
alias hdmi-color-fix='sh ~/bashscripts/hdmi-colour-fix.sh'
# Git
## Git aliases
alias g='git'
alias gfu='git fetch upstream'
alias gfo='git fetch origin'
alias gr='git rebase'
alias gpull='git pull'
alias gs='git status'
alias gc='git checkout'
alias gl="git log --pretty=format:'%Cblue%h%Creset%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative"
alias gbranches='git branch -a'
alias gnb='git checkout -b'
alias gnewbranch='git checkout -b'
alias grmbranch='git branch -d'
alias gd='git diff'
alias gss='git stash save'
alias gsp='git stash pop'
alias gsl='git stash list'
alias ga='git add'
alias gaa='git add -A'
alias gcom='git commit'
alias gcommam='git add -A && git commit -m'
alias gcomma='git add -A && git commit'
alias gcommend='git add -A && git commit --amend --no-edit'
alias gm='git merge'
alias gcp='git cherry-pick'
alias gpoh='git push origin HEAD'
alias grom='git rebase origin/master'
alias gcd='cd ~/repos/'
### From https://docs.gitlab.com/ee/user/project/merge_requests/#checkout-merge-requests-locally : e.g. gcmr upstream 12345
gcmr() { git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2; }
### This function prunes references to deleted remote branches and
### deletes local branches that have been merged and/or deleted from the remotes.
### It is intended to be run when on a master branch, and warns when it isn't.
gclean (){
local BRANCH=`git rev-parse --abbrev-ref HEAD`
# Warning if not on a master* branch
if [[ $BRANCH != master* ]]
then
echo -e "\e[91m!! WARNING: It looks like you are not on a master branch !!\e[39m"
read -r -p "Are you sure you want to continue? [y/N] " response
if ! [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo "Aborted. Nothing was changed."
return 1
fi
fi
echo "Simulating a clean on $BRANCH ..." \
&& echo "===== 1/2: simulating pruning origin =====" \
&& git remote prune origin --dry-run \
&& echo "===== 2/2: simulating cleaning local branches merged to $BRANCH =====" \
&& git branch --merged $BRANCH | grep -v "^\**\s*master" \
&& echo "=====" \
&& echo "Simulation complete."
read -r -p "Do you want to proceed with the above clean? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo "Running a clean on $BRANCH ..."
echo "===== 1/2: pruning origin =====" \
&& git remote prune origin \
&& echo "===== 2/2: cleaning local branches merged to $BRANCH =====" \
&& git branch --merged $BRANCH | grep -v "^\**\s*master" | xargs git branch -d \
&& echo "=====" \
&& echo "Clean finished."
else
echo "Aborted. Nothing was changed."
fi
}
### Sync function for my current workflow, which only has a remote origin.
### Fetches origin and rebases current branch from origin.
gsync (){
local BRANCH=`git rev-parse --abbrev-ref HEAD`
echo "Syncing the current branch: $BRANCH"
echo "===== 1/2: fetching origin =====" \
&& git fetch origin \
&& echo "===== 2/2: rebasing $BRANCH =====" \
&& git rebase origin/$BRANCH \
&& echo "=====" \
&& echo "Syncing finished."
}
### Sync function for my previous workflow, which had upstream+originfork+local.
### Syncs local and origin branch from a remote: runs a fetch from specified remote + rebase local + push to origin.
OLDgsync (){
local BRANCH=`git rev-parse --abbrev-ref HEAD`
echo "Syncing the current branch: $BRANCH"
echo "===== 1/3: fetching $1 =====" \
&& git fetch $1 \
&& echo "===== 2/3: rebasing $BRANCH =====" \
&& git rebase $1/$BRANCH \
&& echo "===== 3/3: pushing to origin/$BRANCH =====" \
&& git push origin $BRANCH \
&& echo "=====" \
&& echo "Syncing finished."
}
### Function to take git interactive rebase argument. e.g.: gir 2
gri() { git rebase -i HEAD~$1; }
gir() { git rebase -i HEAD~$1; }
### Function to undo all changes (including stages) back to the last commit, with a confirmation.
gundoall () {
echo "WARNING: This will delete all untracked files, and undo all changes since the last commit."
read -r -p "Are you sure? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo "===== 1/2: git reset --hard HEAD =====" \
&& git reset --hard HEAD \
&& echo "===== 2/2: git clean -fd \$(git rev-parse --show-toplevel) =====" \
&& git clean -fd $(git rev-parse --show-toplevel)
else
echo "Aborted. Nothing was changed."
fi
}
## git bash completion for aliases
# To Setup:
# 1) Save the .git-completion.bash file found here:
# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
# 2) Add the following lines to your .bash_profile, be sure to reload (for example: source ~/.bash_profile) for the changes to take effect:
if [ -f ~/bashscripts/git-completion.bash ]; then
. ~/bashscripts/git-completion.bash
# Add git completion to the aliases: you must manually match each of your aliases to the respective function for the git command defined in git-completion.bash.
__git_complete g __git_main
__git_complete gc _git_checkout
__git_complete gnb _git_checkout
__git_complete gnewbranch _git_checkout
__git_complete gm _git_merge
__git_complete grmbranch _git_branch
__git_complete gr _git_rebase
__git_complete gl _git_log
__git_complete ga _git_add
__git_complete gd _git_diff
__git_complete gcom _git_commit
__git_complete gcomma _git_commit
__git_complete gcmr _git_ls_remote
__git_complete gpull _git_pull
__git_complete gsync _git_fetch
fi
## Custom git prompt configuration https://github.com/magicmonty/bash-git-prompt
# Set config variables first
GIT_PROMPT_ONLY_IN_REPO=0
# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status
# Lucas: change fetch interval to 60 minutes (default is 5)
GIT_PROMPT_FETCH_TIMEOUT=60
if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then
GIT_PROMPT_ONLY_IN_REPO=1
source $HOME/.bash-git-prompt/gitprompt.sh
fi
alias getDev="git fetch && git checkout develop && git pull"
alias getMas="git fetch && git checkout master && git pull"
alias gs="git status"
alias ns="npm run start"
alias nt="npm test"
alias cdP="cd ~/workshop"
alias c="clear"
alias r="reset"
alias sbr="source ~/.bash_profile"
alias ownAll="sudo chown -R $USER:$USER *"
alias kad='docker container kill $(docker ps -q)'
alias docip='docker inspect --format='"'"'{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'"'"' $(docker ps -q)'
cdP