-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_gitrc
105 lines (84 loc) · 3.95 KB
/
.bash_gitrc
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
#!/bin/bash
alias g='git' #'hub'
#Git Flow
alias gff='git flow feature'
alias gffs='gff start'
alias gffp='gff publish'
alias gfff='gff finish'
#Basic Git Commands
alias gb='g branch -vv'
alias gc='g checkout'
alias gci='g commit'
alias gcommend='g commit --amend --no-edit'
alias gt='g tag -a'
alias gpush='g push --follow-tags'
alias gtp='git fetch origin --tags --force --prune --prune-tags'
#Stashing
alias gstash='g stash --keep-index' #stash only unstaged changes to tracked files
alias gstaash='g stash --include-untracked' #stash untracked AND tracked files
alias sstaaash='g stash --all' #stash ignored, untracked, and tracked files
alias gstashLast='g show stash@{0}'
alias gstashList='g stash list --date=local'
alias gstashPretty='g stash list --pretty=format:"%C(red)%h%C(reset) - %C(dim yellow)(%C(bold magenta)%gd%C(dim yellow))%C(reset) %<(70,trunc)%s %C(green)(%cr) %C(bold blue)<%an>%C(reset)"'
#Diff
alias gd='g diff'
alias gds='gd --staged'
alias gf='git fetch --prune -v'
alias gmso='git merge --strategy-option ours'
alias gmst='git merge --strategy-option theirs'
alias gprune='git remote prune origin'
#Branch Management
function listLocalBranches() { g fetch --prune && git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' }
alias gdeletelocalbranches="listLocalBranches | xargs git branch -d"
alias gdeletelocalbranchesFORCED="listLocalBranches | xargs git branch -D"
alias gdb="listLocalBranches | xargs git branch -D"
alias gpull='git pull --ff-only' #--ff-only prevents a pull if it requires a merge or rebase
alias gpush='git push --set-upstream origin `git rev-parse --abbrev-ref HEAD`' # creates the remote branch
alias forcePush='gpush --force-with-lease'
alias gr="git checkout --" #Git 'Revert'
alias gs='git status'
alias gss='gs --short --branch'
alias gu='git reset --soft HEAD~' #Undo commits made on current branch (preserve changes)
alias gpick='git cherry-pick -x'
# Tags
function listTags() { git tag -l "$1*" }
# https://gist.github.com/shsteimer/7257245#gistcomment-2623569
function deleteRemoteTags() { git push -d origin $(listTags $1) }
function deleteLocalTags() { git tag -d $(listTags $1) }
function deleteTags() {
echo "Deleting remote tags..."
deleteRemoteTags $1
echo "Deleting local tags..."
deleteLocalTags $1
}
alias pruneTags='git fetch origin --tags --force --prune --prune-tags'
## Rebasing
alias grc='g rebase --continue'
alias gra='g rebase --abort'
alias grs='g rebase --skip'
#Git Modules - http://blog.jacius.info/git-submodule-cheat-sheet/
alias gmodi='git submodule update --init' #Git Module Init (pull repo content for all modules)
# Git Repo Logging, Add '-{N}' to these commands to see the last N log entries
# %C=color, %h=commitHash, %ad=AuthorDate, %d=ref names, %s=subject, %cn=committer name
commonLogOpts="--no-merges"
export gitFormat="%C(yellow)%h %Creset %ad%Cred%d %Creset%s%Cblue [%an] (%cn)"
alias gl='g log $commonLogOpts --pretty=format:"$gitFormat" --decorate --date=relative'
alias glm='gl --max-parents=2'
alias gll='g log $commonLogOpts --pretty=format:"$gitFormat" --numstat'
# log branches
alias glb="g for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"
#https://stackoverflow.com/a/9074343
# log the graph
alias glg="g log $commonLogOpts --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
#See all the commits related to a file, with the diff of the changes
alias gfilelog='g log -u'
alias gfl='gfilelog'
function gdeletedIn() { g log -1 -- **/$1 }
#See the diff of the last commit
alias gdlc='g diff --cached HEAD^'
#Get diff of a revision
function gdr() { g diff "$1"^.."$1"; }
#Get the long listing of a commit revision
function glc() { gll "$1"^.."$1"; }
#Create a branch for an issue
function gbi() { gc -b issue-$1; }